Skip to content

ENH: Accept pd.NA as a float #56797

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

Closed
1 of 3 tasks
mdruiter opened this issue Jan 9, 2024 · 3 comments
Closed
1 of 3 tasks

ENH: Accept pd.NA as a float #56797

mdruiter opened this issue Jan 9, 2024 · 3 comments
Labels
Closing Candidate May be closeable, needs more eyeballs Enhancement Needs Triage Issue that has not been reviewed by a pandas team member PDEP missing values Issues that would be addressed by the Ice Cream Agreement from the Aug 2023 sprint

Comments

@mdruiter
Copy link
Contributor

mdruiter commented Jan 9, 2024

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

In float[pyarrow] data, missings values are pd.NA. I can easily convert these frames to floats:

pd.Series([pd.NA], dtype='float[pyarrow]').astype('float')

0 NaN
dtype: float64

But in the pd.Series constructor, I cannot use pd.NAs:

pd.Series([pd.NA], dtype='float')

TypeError: float() argument must be a string or a real number, not 'NAType'

Is this by design?

Feature Description

It would be so much more convenient if pd.NA would 'just' be recognized as a np.nan in float context...

Alternative Solutions

Using .astype('float') is a workaround but makes code less generic.

Additional Context

I searched for issues like this or a design statement, but could not find anything about this specific thing, which surprised me as it feels like a common inconvenience.

@mdruiter mdruiter added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 9, 2024
@mdruiter
Copy link
Contributor Author

mdruiter commented Jan 9, 2024

I think I found a relevant statement after all: #32265 (comment)

@rhshadrach rhshadrach added the PDEP missing values Issues that would be addressed by the Ice Cream Agreement from the Aug 2023 sprint label Jan 9, 2024
@rhshadrach
Copy link
Member

It would be so much more convenient if pd.NA would 'just' be recognized as a np.nan in float context...

This is the essentially the direction pandas plans to head in.

cc @phofl @jorisvandenbossche - I think this issue is likely duplicative of others we have on np.nan, pd.NA. Good to close?

@rhshadrach rhshadrach added the Closing Candidate May be closeable, needs more eyeballs label Jan 9, 2024
@phofl
Copy link
Member

phofl commented Jan 9, 2024

Yes

@phofl phofl closed this as completed Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closing Candidate May be closeable, needs more eyeballs Enhancement Needs Triage Issue that has not been reviewed by a pandas team member PDEP missing values Issues that would be addressed by the Ice Cream Agreement from the Aug 2023 sprint
Projects
None yet
Development

No branches or pull requests

3 participants