Skip to content

Make get_loc with nan for FloatIndex consistent with other index types #39382

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 10 commits into from
Feb 3, 2021

Conversation

phofl
Copy link
Member

@phofl phofl commented Jan 24, 2021

  • tests added / passed
  • Ensure all linting tests pass, see here for how to run them
  • whatsnew entry

Have not added a whatsnew because I am not sure if 2 is expected here. You could also make a point for retruning nan. But to handle these cases consistently, we have to check for method here

@phofl phofl added the Indexing Related to indexing on series/frames, not to indexes themselves label Jan 24, 2021
@jbrockmendel
Copy link
Member

i think test failures should be fixed by merging master

@phofl phofl changed the title Get loc nan Make get_loc with nan for FloatIndex consistent with other index types Jan 25, 2021
@@ -57,7 +57,10 @@ cdef class {{name}}Engine(IndexEngine):
with warnings.catch_warnings():
# e.g. if values is float64 and `val` is a str, suppress warning
warnings.filterwarnings("ignore", category=FutureWarning)
indexer = values == val
if cmath.isnan(val):
Copy link
Member

Choose a reason for hiding this comment

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

probably should use tempita to only do this check for FloatEngine

might be able to use something in the cnp namespace for the isnan check

Copy link
Member Author

Choose a reason for hiding this comment

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

If we do this only for float, test_slice_locs_na raises from /indexes/test_base.py

Actually we don't need imports I think. Changed it

Copy link
Member

Choose a reason for hiding this comment

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

util.is_nan might work

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah thx.

@@ -57,7 +57,10 @@ cdef class {{name}}Engine(IndexEngine):
with warnings.catch_warnings():
# e.g. if values is float64 and `val` is a str, suppress warning
warnings.filterwarnings("ignore", category=FutureWarning)
indexer = values == val
if val != val:
indexer = values != values
Copy link
Member

Choose a reason for hiding this comment

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

something like

{{ if dtype in ["float64", "float32"]}}
if val != val:
    indexer = np.isnan(values)
else:
    indexer = values == val
{{else}}
indexer = values == val
{{endif}}

Copy link
Member Author

Choose a reason for hiding this comment

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

I did the same thing yesterday, this caused the test to fail. Weird...

@jreback jreback added this to the 1.3 milestone Feb 2, 2021
@jreback
Copy link
Contributor

jreback commented Feb 2, 2021

@phofl can you merge master. ok with fixing this here or in followup to raise.

@phofl
Copy link
Member Author

phofl commented Feb 2, 2021

This is raising now if nan is not in Index

@jreback jreback merged commit 388ff01 into pandas-dev:master Feb 3, 2021
@jreback
Copy link
Contributor

jreback commented Feb 3, 2021

very nice!

this may close other issues (hard to search for but looking for indexing and nan)

@phofl phofl deleted the get_loc_nan branch February 4, 2021 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants