Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Support all real number dtypes in dataframe editor #21295

Merged
merged 2 commits into from
Aug 30, 2023

Conversation

jitseniesen
Copy link
Member

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)

This is a small PR which uses the new function pandas.api.types.is_any_real_numeric_dtype() to decide whether a Pandas dtype is a real number and thus gets the background colouring of numbers in the Dataframe editor. This allows us to supports the nullable integer types and also numeric types that were previously not supported like numpy.int16. A test is also included.

This PR imports pandas inside a function. As far as I can see, no part of Spyder explicitly imports pandas but I think that pandas is always imported when a Dataframe editor is opened, so this should not be a problem.

Screenshot after:

df-new

Screenshot before:

df-old

These are produced using the following code, from issue #21022:

import pandas as pd

vals = [1, 2, 3, 4, 5]
vals_na = [1, 2, 3, None, 5]

df = pd.DataFrame({
    'old': pd.Series(vals),
    'old_na': pd.Series(vals_na),
    'new': pd.Series(vals, dtype='Int64'),
    'new_na': pd.Series(vals_na, dtype='Int64')
})

Issue(s) Resolved

Fixes #21222

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

In particular, this supports the nullable dtypes.
Also, add a test.
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.

A couple of small suggestions for you, the rest looks good to me.

@ccordoba12 ccordoba12 changed the title Support all real number dtypes in dataframe editor PR: Support all real number dtypes in dataframe editor Aug 28, 2023
@ccordoba12 ccordoba12 added this to the v6.0alpha3 milestone Aug 28, 2023
* Wider except clause in case the import fails for any reason
* Formatting

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

A couple of small suggestions fo you, the rest looks good to me.

Thanks, I applied all the suggestions.

@ccordoba12 ccordoba12 modified the milestones: v6.0alpha3, v6.0alpha2 Aug 30, 2023
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 46984a8 into spyder-ide:master Aug 30, 2023
@jitseniesen jitseniesen deleted the pandas-nullable branch December 8, 2023 22:12
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.

DataFrame Editor background coloring does not support pandas.Int*Dtype dtypes
2 participants