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.__getitem__ with downstream scalars #32684

Merged
merged 6 commits into from
Mar 19, 2020

Conversation

jbrockmendel
Copy link
Member

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

cc @spencerclark I think this fixes a subset of the issues reported in pydata/xarray#3751, can you confirm?

@jorisvandenbossche IIRC geopandas scalars not being recognized by lib.is_scalar has caused some issues there; does this address any of those?

# check for is_list_like/slice instead of is_scalar to allow non-standard
# scalars through, e.g. cftime.datetime needed by xarray
# https://github.com/pydata/xarray/issues/3751
key_is_scalar = not is_list_like(key) and not isinstance(key, slice)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is really really sketch, why don't we just fix is_scalar?

also pls add a test if you can for this

Copy link
Member Author

Choose a reason for hiding this comment

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

why don't we just fix is_scalar?

Depends on what we want is_scalar to mean. We could re-write is_scalar to just match this (actually more performant than what we have now), but it isn't really viable to add checks for any custom scalar that downstream libraries might implement.

Going to wait to hear from the downstream folks on if this actually solves their problem(s)

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually think is_scalar should just be this its much more generic and future proof

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm so changing is_scalar to just match this is breaking a bunch of tests bc is_scalar(some_lambda_func) is returning True

Copy link
Contributor

Choose a reason for hiding this comment

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

right you might need some more exclusions, e.g. callabes

Copy link
Member Author

Choose a reason for hiding this comment

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

so the trouble im facing ATM is that TimeGrouper is being recognized as a scalar

Copy link
Member Author

Choose a reason for hiding this comment

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

The more I look at this the more skeptical I am of trying to amend is_scalar

Copy link
Contributor

Choose a reason for hiding this comment

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

since we don't actually have a test case for this, am inclined to close.

Copy link
Member Author

Choose a reason for hiding this comment

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

coming up with a test case isnt difficult, just need to settle on an approach.

@jreback jreback added the Indexing Related to indexing on series/frames, not to indexes themselves label Mar 14, 2020
@spencerkclark
Copy link
Contributor

Thanks @jbrockmendel -- sorry I just saw this now. Yes, as written, this change indeed fixes the remaining issue for us, though I think @jreback's suggestion would work too.

@jbrockmendel
Copy link
Member Author

Updated with a better implementation, and a test that fails in master: df.dtypes[some_dtype] currently raises, is fixed here.

@jreback jreback added this to the 1.1 milestone Mar 19, 2020
@jreback jreback merged commit f47516d into pandas-dev:master Mar 19, 2020
@jreback
Copy link
Contributor

jreback commented Mar 19, 2020

much better, thanks.

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