Skip to content

Conversation

@jitseniesen
Copy link
Member

@jitseniesen jitseniesen commented Jun 8, 2025

Description of Changes

  • Wrote at least one-line docstrings (for any new functions)
  • Added unit test(s) covering the changes (if testable)
  • Included a screenshot or animation (if affecting the UI, see Licecap)

Support Polars data frames in the Variable Explorer. The user can open the Polars dataframe in Spyder, in which case the kernel converts it to a Pandas dataframe. This is so that we don't need to have polars installed in Spyder's runtime environment, only in the console environment. The disadvantage is firstly that the data frame can not be edited in Spyder, because converting from Polars to Pandas and then back to Polars does probably not always work. Therefore, the dataframe editor is read only. Secondly, the conversion from Polars to Pandas in the console environment only works if pandas and pyarrow are installed in the console environment. Thus, I added a new error message to handle the case where opening an editor in the Variable Explorer raises an ModuleNotFoundError in the kernel.

Before this PR, Polars dataframes opened in the Object Explorer which is not very useful.

This PR requires spyder-ide/spyder-kernels#549.

Video of opening a Polars dataframe, when polars, pandas and pyarrow are installed in the console environment but only pandas in the runtime environment:

polars-with.mp4

Video of the error message shown if the user tries to open a Polars dataframe but pyarrow is not installed in the console environment:

polars-without.mp4

Issue(s) Resolved

Fixes #20281

Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

I certify the above statement is true and correct:
Jitse Niesen

Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvement, thanks @jitseniesen! Two tiny suggestions, the rest looks good to me.

Models can have a flags() function to override the behaviour of
the base class, but the Qt classes for views do not have a flags()
function.
Also add tests and add or improve docstrings.
If retrieving a variable from the kernel fails due to a
ModuleNotFoundError raised by call_kernel(), then show an error
message instructing the user to install the missing module in the
console environment.

This error occurs if a user tries to retrieve a Polars dataframe,
because the kernel will transform it to a Pandas dataframe and
this fails if pandas is not installed in the kernel environment.
…r-kernels.git --update external-deps/spyder-kernels

subrepo:
  subdir:   "external-deps/spyder-kernels"
  merged:   "7987954c8"
upstream:
  origin:   "https://github.com/spyder-ide/spyder-kernels.git"
  branch:   "master"
  commit:   "7987954c8"
git-subrepo:
  version:  "0.4.9"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "30db3b8"
Apply suggestions from code review

Co-authored-by: Carlos Cordoba <[email protected]>
@jitseniesen
Copy link
Member Author

@ccordoba12 Thanks for your suggestions. I committed them, updated the PR to incorporate the merged PR in spyder-kernels and rebased, so this is ready to be merged as far as I am concerned.

Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jitseniesen!

@ccordoba12 ccordoba12 merged commit a167267 into spyder-ide:master Jul 16, 2025
21 checks passed
@jitseniesen jitseniesen deleted the polars branch July 16, 2025 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make Polars DataFrame be able to open on Variable Explorer.

2 participants