Skip to content

BUG: handle NaNs in FloatingArray.equals #44390

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

Merged
merged 4 commits into from
Nov 13, 2021

Conversation

jbrockmendel
Copy link
Member

@jbrockmendel jbrockmendel commented Nov 11, 2021

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Thanks! One small comment

data = np.array([1.0, np.nan, 3.0], dtype=np.float64)

left = FloatingArray(data, mask)
assert left.equals(left)
Copy link
Member

Choose a reason for hiding this comment

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

Could you do something like left2 = FloatingArray(data.copy(), mask.copy()) to create the other array to test equality with? I would just avoid the special case of "identical" objects (in case we might add a fastpath for that in the future)

Copy link
Member Author

Choose a reason for hiding this comment

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

updated; is this what you had in mind?

Copy link
Member

Choose a reason for hiding this comment

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

That's fine!
Can you add a small whatsnew note?

@jorisvandenbossche jorisvandenbossche changed the title BUG: FloatingArray.equals BUG: handle NaNs in FloatingArray.equals Nov 11, 2021
@jreback jreback added the ExtensionArray Extending pandas with custom dtypes or arrays. label Nov 12, 2021
@jreback jreback added this to the 1.4 milestone Nov 12, 2021
@jreback
Copy link
Contributor

jreback commented Nov 12, 2021

do we have reference docs for these anywhere? (i don't remember), if so can you add otherwise lgtm

@jreback
Copy link
Contributor

jreback commented Nov 12, 2021

actually would be great to tests Series equals with FloatDtype (does it dispatch to this?)

@jorisvandenbossche
Copy link
Member

do we have reference docs for these anywhere? (i don't remember), if so can you add otherwise lgtm

Yes. The relevant one for users is https://pandas.pydata.org/docs/dev/reference/api/pandas.Series.equals.html#, and the ExtensionArray version is also listed: https://pandas.pydata.org/docs/dev/reference/api/pandas.api.extensions.ExtensionArray.equals.html

actually would be great to tests Series equals with FloatDtype (does it dispatch to this?)

Yes, it does dispatch, and that's already tested.

@jreback
Copy link
Contributor

jreback commented Nov 12, 2021

where is the series test explicitly added here?

@jorisvandenbossche
Copy link
Member

It is not added here because we already have a general extension test (test_equals) that ensures both DataFrame and Series dispatch to the EA method.

@jreback
Copy link
Contributor

jreback commented Nov 12, 2021

sure but do we have an example that was failing with Float dtypes that check nans - we couldn't have as it would have failed - so need this case

@jorisvandenbossche
Copy link
Member

We have a lot of specific tests in the /tests/arrays that are not all repeated each time for Series or DataFrame. And I think that is fine.

@jreback jreback merged commit 7e51bd7 into pandas-dev:master Nov 13, 2021
@jbrockmendel jbrockmendel deleted the bug-floatarray-equals branch November 13, 2021 17:29
@jbrockmendel
Copy link
Member Author

i think this wasnt ready, had failures on older numpys

@jorisvandenbossche
Copy link
Member

It seems the equal_nan keyword is new in numpy 1.19 (https://numpy.org/doc/stable/reference/generated/numpy.array_equal.html)

@jbrockmendel
Copy link
Member Author

shimmed a fix for this into #44428

@jorisvandenbossche
Copy link
Member

Can you quickly put it in its own PR? That seems easier to merge it quickly, while the other PR still needs to be reviewed?

nickleus27 pushed a commit to nickleus27/pandas that referenced this pull request Nov 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: FloatingArray.equals should consider NaNs in same location as equal
3 participants