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

BUG: Series.get with Float64Index and numpy nan returns empty Series #8569

Closed
willpan opened this issue Oct 16, 2014 · 7 comments · Fixed by #16619
Closed

BUG: Series.get with Float64Index and numpy nan returns empty Series #8569

willpan opened this issue Oct 16, 2014 · 7 comments · Fixed by #16619
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@willpan
Copy link

willpan commented Oct 16, 2014

I tried to use series.get(x) (where x is np.nan in some instance) and the result was an empty series. It seems like it should just return None if it can't be found.

import pandas as pd
import numpy as np

series = pd.Series(range(0, 10))
series.get(np.nan) 
# returns None

series = series.reindex(pd.Float64Index(range(0, 10)))

series.get(10) 
# This correctly returns None

series.get(np.nan) 
# returns empty series with empty Float64Index

series.get(np.nan, np.nan) 
# same thing
@jreback
Copy link
Contributor

jreback commented Oct 16, 2014

indexing with np.nan on any index doesn't make much sense. what are you trying to do?

maybe s[s.isnull()]?

@willpan
Copy link
Author

willpan commented Oct 16, 2014

Well, it's being called like this:

some_series = some_series.map(lambda x: some_other_series.get(x))

@jreback
Copy link
Contributor

jreback commented Oct 16, 2014

and why would you do that? again simply use s.isnull() that's what it is for.

@willpan
Copy link
Author

willpan commented Oct 16, 2014

The code (I ran across the difference while regression testing, I'm not the original author) is basically trying to merge a Series into a DataFrame so the actual code was something like:

df[new_col] = df[lookup_col].map(lambda x: some_other_series.get(x))

I just noticed the behavior was inconsistent between versions (I'm going from 0.9 to 14.1).

@jreback
Copy link
Contributor

jreback commented Oct 16, 2014

well, that is quite inefficient, and not what you want to do anyhow, is their a reason you are not using
a) merge, or b) df[lookup_col].map(some_other_series) ?

@willpan
Copy link
Author

willpan commented Oct 16, 2014

I'm going to end up replacing it with the second option. I work with a lot of people who write code as a part of their job, but who aren't programmers, and they don't always make the best choices.

Anyways, I thought that the result of series.get(np.nan) was unusual, but feel free to close if this isn't worth it. Thanks.

@jreback
Copy link
Contributor

jreback commented Oct 16, 2014

I do appreciate the report (esp since it's an apparent change from a long ago version)

I may link this to another issue
technically a test like thks is ok

let me see

dsm054 added a commit to dsm054/pandas that referenced this issue Jun 7, 2017
dsm054 added a commit to dsm054/pandas that referenced this issue Jun 7, 2017
dsm054 added a commit to dsm054/pandas that referenced this issue Jun 7, 2017
dsm054 added a commit to dsm054/pandas that referenced this issue Jun 7, 2017
dsm054 added a commit to dsm054/pandas that referenced this issue Jun 7, 2017
dsm054 added a commit to dsm054/pandas that referenced this issue Jun 7, 2017
@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate and removed Usage Question labels Jun 8, 2017
@jreback jreback added this to the 0.20.3 milestone Jun 8, 2017
TomAugspurger pushed a commit to TomAugspurger/pandas that referenced this issue Jul 6, 2017
TomAugspurger pushed a commit that referenced this issue Jul 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants