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: Fix MultiIndex .loc with all numpy arrays #19772

Merged
merged 1 commit into from
Feb 23, 2018

Conversation

spacesphere
Copy link
Contributor

@@ -767,6 +767,7 @@ Indexing
- Bug in :class:`IntervalIndex` where empty and purely NA data was constructed inconsistently depending on the construction method (:issue:`18421`)
- Bug in :func:`IntervalIndex.symmetric_difference` where the symmetric difference with a non-``IntervalIndex`` did not raise (:issue:`18475`)
- Bug in :class:`IntervalIndex` where set operations that returned an empty ``IntervalIndex`` had the wrong dtype (:issue:`19101`)
- Bug in indexing where nested indexers having only numpy arrays are handled incorrectly (:issue:`19686`)
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 move to the mult-index section

@@ -711,3 +711,36 @@ def test_identity_slice_returns_new_object(self):

original_series[:3] = [7, 8, 9]
assert all(sliced_series[:3] == [7, 8, 9])

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 Index here as well.

(list, tuple, set, slice, np.ndarray, Series))
@pytest.mark.parametrize('indexer_type_2',
(list, tuple, set, slice, np.ndarray, Series))
def test_loc_getitem_nested_indexer(self, indexer_type_1, indexer_type_2):
Copy link
Contributor

Choose a reason for hiding this comment

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

add the gh issue number & a 1-liner of what you are testing


keys = ([10, 20], [2, 3])
types = (indexer_type_1, indexer_type_2)
# check indexers with all the combinations of nested objects
Copy link
Contributor

Choose a reason for hiding this comment

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

blank line here

df = pd.DataFrame(np.arange(len(index)), index=index, columns=['Data'])

keys = ([10, 20], [2, 3])
types = (indexer_type_1, indexer_type_2)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you might be able to use np.ix_ for this, we also have some utilities in pandas/core/indexing.py

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex labels Feb 19, 2018
@codecov
Copy link

codecov bot commented Feb 20, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@b585e3b). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #19772   +/-   ##
=========================================
  Coverage          ?    91.6%           
=========================================
  Files             ?      150           
  Lines             ?    48887           
  Branches          ?        0           
=========================================
  Hits              ?    44785           
  Misses            ?     4102           
  Partials          ?        0
Flag Coverage Δ
#multiple 89.98% <100%> (?)
#single 41.8% <100%> (?)
Impacted Files Coverage Δ
pandas/core/indexing.py 93.02% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b585e3b...f4e4b99. Read the comment docs.

a = [10, 20, 30]
b = [1, 2, 3]
index = pd.MultiIndex.from_product([a, b])
df = pd.DataFrame(np.arange(len(index)), index=index, columns=['Data'])
Copy link
Contributor

Choose a reason for hiding this comment

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

you need to add dtype='int64' otherwise this won't match on windows (as np.arange defaults to int32)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, thanks

@spacesphere spacesphere force-pushed the mi-loc-19686 branch 3 times, most recently from 00c7ccd to f4e4b99 Compare February 22, 2018 03:40
@jreback jreback added this to the 0.23.0 milestone Feb 22, 2018
@jreback
Copy link
Contributor

jreback commented Feb 22, 2018

lgtm ping on green.

@spacesphere
Copy link
Contributor Author

@jreback all the checks have already finished

@jreback jreback merged commit 572476f into pandas-dev:master Feb 23, 2018
@jreback
Copy link
Contributor

jreback commented Feb 23, 2018

thanks!

@spacesphere spacesphere deleted the mi-loc-19686 branch February 23, 2018 03:50
harisbal pushed a commit to harisbal/pandas that referenced this pull request Feb 28, 2018
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 MultiIndex
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: MultiIndex .loc fails with all numpy arrays
2 participants