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: df.iloc[:, :1] with EA column #32959

Merged
merged 15 commits into from Apr 10, 2020
Merged

Conversation

jbrockmendel
Copy link
Member

@jbrockmendel jbrockmendel commented Mar 23, 2020

@jbrockmendel jbrockmendel added Bug Indexing Related to indexing on series/frames, not to indexes themselves labels Mar 23, 2020
pandas/tests/extension/base/getitem.py Outdated Show resolved Hide resolved
pandas/core/internals/blocks.py Outdated Show resolved Hide resolved
pandas/core/internals/blocks.py Outdated Show resolved Hide resolved
@jbrockmendel
Copy link
Member Author

im now thinking the test doesnt belong in extension tests; if it were to fail (e.g. in the status quo), that wouldnt indicate that the EA author needed to fix somthing

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

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.

see earlier comments

@jreback jreback added this to the 1.1 milestone Mar 29, 2020
@jbrockmendel
Copy link
Member Author

i think comments have been addressed @jorisvandenbossche, can you confirm?

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.

Can you add some more test cases (the other possibilities I mentioned, with xfails for now if need be)

raise AssertionError(
"invalid slicing for a 1-ndim ExtensionArray", first
)
elif not (first == slice(None) or first == slice(1)):
Copy link
Member

Choose a reason for hiding this comment

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

I think the check for slice(1) is too strict. Eg, you can slice with out of bounds ends, like slice(2), and that should work as well

pandas/core/internals/blocks.py Outdated Show resolved Hide resolved
# return same dims as we currently have
if not isinstance(slicer, tuple) and self.ndim == 2:
# reached via getitem_block via _slice_take_blocks_ax0
Copy link
Member

Choose a reason for hiding this comment

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

Could also put this check in getitem_block or _slice_take_blocks_ax0 to ensure that _slice always gets the correct tuple of slices?

Copy link
Member

Choose a reason for hiding this comment

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

Or, directly check the value? As here you convert it to a len-2 tuple, and then in a next step, you convert the tuple back to a slice?

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 one way to avoid this PITA would be to have 2D EAs...

@jbrockmendel
Copy link
Member Author

@jorisvandenbossche have your concerns/comments been addressed here?

@jbrockmendel
Copy link
Member Author

gentle ping @jorisvandenbossche

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

minor test comment

result = df.iloc[:, :1]
self.assert_frame_equal(result, df)

result = df.iloc[:, :2]
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add some df.iloc[:, -1:] as well

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+green

@jreback
Copy link
Contributor

jreback commented Apr 10, 2020

needs a rebase as well

@jreback jreback merged commit e7cbe6d into pandas-dev:master Apr 10, 2020
@jreback
Copy link
Contributor

jreback commented Apr 10, 2020

thanks @jbrockmendel

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: iloc on DataFrame[ea]
4 participants