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

Comments

Projects
None yet
2 participants
@willpan

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

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Oct 16, 2014

Contributor

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

maybe s[s.isnull()]?

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

This comment has been minimized.

Show comment
Hide comment
@willpan

willpan Oct 16, 2014

Well, it's being called like this:

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

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

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Oct 16, 2014

Contributor

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

Contributor

jreback commented Oct 16, 2014

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

@willpan

This comment has been minimized.

Show comment
Hide comment
@willpan

willpan 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).

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

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Oct 16, 2014

Contributor

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) ?

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

This comment has been minimized.

Show comment
Hide comment
@willpan

willpan 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.

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

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Oct 16, 2014

Contributor

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

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 this to the 0.20.3 milestone Jun 8, 2017

@jreback jreback closed this in #16619 Jun 8, 2017

jreback added a commit that referenced this issue Jun 8, 2017

Kiv added a commit to Kiv/pandas that referenced this issue Jun 11, 2017

stangirala added a commit to stangirala/pandas that referenced this issue Jun 11, 2017

TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue Jul 6, 2017

TomAugspurger added 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