-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DEPR: remove Panel-specific parts of core.indexing #25567
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c47d36f
DEPR: remove Panel-specific parts of core.indexing
simonjayhawkins 6e485bd
Merge remote-tracking branch 'upstream/master' into panel-indexing
simonjayhawkins 348c595
add new error if ndim > 2 and remove failing test
simonjayhawkins 451a967
minor change
simonjayhawkins 63495a6
Merge remote-tracking branch 'upstream/master' into panel-indexing
simonjayhawkins cc22e5f
Merge remote-tracking branch 'upstream/master' into panel-indexing
simonjayhawkins bc505bc
Merge remote-tracking branch 'upstream/master' into panel-indexing
simonjayhawkins f39a75f
add 3-d indexer setting and getting tests
simonjayhawkins c1c200e
Merge remote-tracking branch 'upstream/master' into panel-indexing
simonjayhawkins fac9442
resolve merge conflict
simonjayhawkins be19f78
Merge remote-tracking branch 'upstream/master' into panel-indexing
simonjayhawkins 26f2ac2
change exception raised and add test
simonjayhawkins 1de10b5
fix linting errors
simonjayhawkins 8d2ab43
Merge remote-tracking branch 'upstream/master' into panel-indexing
simonjayhawkins 496ab7d
Merge remote-tracking branch 'upstream/master' into panel-indexing
simonjayhawkins 29cde25
Merge remote-tracking branch 'upstream/master' into panel-indexing
simonjayhawkins eaf161b
fix-up test_ndframe_indexing_raises
simonjayhawkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
from pandas.core.dtypes.common import ( | ||
ensure_platform_int, is_float, is_integer, is_integer_dtype, is_iterator, | ||
is_list_like, is_scalar, is_sequence, is_sparse) | ||
from pandas.core.dtypes.generic import ABCDataFrame, ABCPanel, ABCSeries | ||
from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries | ||
from pandas.core.dtypes.missing import _infer_fill_value, isna | ||
|
||
import pandas.core.common as com | ||
|
@@ -453,10 +453,6 @@ def _setitem_with_indexer(self, indexer, value): | |
self.obj._maybe_update_cacher(clear=True) | ||
return self.obj | ||
|
||
# set using setitem (Panel and > dims) | ||
elif self.ndim >= 3: | ||
return self.obj.__setitem__(indexer, value) | ||
|
||
# set | ||
item_labels = self.obj._get_axis(info_axis) | ||
|
||
|
@@ -645,9 +641,6 @@ def can_do_equal_len(): | |
elif isinstance(value, ABCDataFrame): | ||
value = self._align_frame(indexer, value) | ||
|
||
if isinstance(value, ABCPanel): | ||
value = self._align_panel(indexer, value) | ||
|
||
# check for chained assignment | ||
self.obj._check_is_chained_assignment_possible() | ||
|
||
|
@@ -693,7 +686,6 @@ def ravel(i): | |
sum_aligners = sum(aligners) | ||
single_aligner = sum_aligners == 1 | ||
is_frame = self.obj.ndim == 2 | ||
is_panel = self.obj.ndim >= 3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we are going to need a new error if self.obj.ndim.ndim > 2 (e.g. a numpy array); need to check both for setting & getting (it *might be already there but not sure about tests) |
||
obj = self.obj | ||
|
||
# are we a single alignable value on a non-primary | ||
|
@@ -705,11 +697,6 @@ def ravel(i): | |
if is_frame: | ||
single_aligner = single_aligner and aligners[0] | ||
|
||
# panel | ||
elif is_panel: | ||
single_aligner = (single_aligner and | ||
(aligners[1] or aligners[2])) | ||
|
||
# we have a frame, with multiple indexers on both axes; and a | ||
# series, so need to broadcast (see GH5206) | ||
if (sum_aligners == self.ndim and | ||
|
@@ -741,38 +728,14 @@ def ravel(i): | |
return ser.reindex(new_ix)._values | ||
|
||
# 2 dims | ||
elif single_aligner and is_frame: | ||
elif single_aligner: | ||
|
||
# reindex along index | ||
ax = self.obj.axes[1] | ||
if ser.index.equals(ax) or not len(ax): | ||
return ser._values.copy() | ||
return ser.reindex(ax)._values | ||
|
||
# >2 dims | ||
elif single_aligner: | ||
|
||
broadcast = [] | ||
for n, labels in enumerate(self.obj._get_plane_axes(i)): | ||
|
||
# reindex along the matching dimensions | ||
if len(labels & ser.index): | ||
ser = ser.reindex(labels) | ||
else: | ||
broadcast.append((n, len(labels))) | ||
|
||
# broadcast along other dims | ||
ser = ser._values.copy() | ||
for (axis, l) in broadcast: | ||
shape = [-1] * (len(broadcast) + 1) | ||
shape[axis] = l | ||
ser = np.tile(ser, l).reshape(shape) | ||
|
||
if self.obj.ndim == 3: | ||
ser = ser.T | ||
|
||
return ser | ||
|
||
elif is_scalar(indexer): | ||
ax = self.obj._get_axis(1) | ||
|
||
|
@@ -785,7 +748,6 @@ def ravel(i): | |
|
||
def _align_frame(self, indexer, df): | ||
is_frame = self.obj.ndim == 2 | ||
is_panel = self.obj.ndim >= 3 | ||
|
||
if isinstance(indexer, tuple): | ||
|
||
|
@@ -805,21 +767,6 @@ def _align_frame(self, indexer, df): | |
else: | ||
sindexers.append(i) | ||
|
||
# panel | ||
if is_panel: | ||
|
||
# need to conform to the convention | ||
# as we are not selecting on the items axis | ||
# and we have a single indexer | ||
# GH 7763 | ||
if len(sindexers) == 1 and sindexers[0] != 0: | ||
df = df.T | ||
|
||
if idx is None: | ||
idx = df.index | ||
if cols is None: | ||
cols = df.columns | ||
|
||
if idx is not None and cols is not None: | ||
|
||
if df.index.equals(idx) and df.columns.equals(cols): | ||
|
@@ -846,24 +793,8 @@ def _align_frame(self, indexer, df): | |
val = df.reindex(index=ax)._values | ||
return val | ||
|
||
elif is_scalar(indexer) and is_panel: | ||
idx = self.obj.axes[1] | ||
cols = self.obj.axes[2] | ||
|
||
# by definition we are indexing on the 0th axis | ||
# a passed in dataframe which is actually a transpose | ||
# of what is needed | ||
if idx.equals(df.index) and cols.equals(df.columns): | ||
return df.copy()._values | ||
|
||
return df.reindex(idx, columns=cols)._values | ||
|
||
raise ValueError('Incompatible indexer with DataFrame') | ||
|
||
def _align_panel(self, indexer, df): | ||
raise NotImplementedError("cannot set using an indexer with a Panel " | ||
"yet!") | ||
|
||
def _getitem_tuple(self, tup): | ||
try: | ||
return self._getitem_lowerdim(tup) | ||
|
@@ -1056,13 +987,6 @@ def _getitem_nested_tuple(self, tup): | |
# has the dim of the obj changed? | ||
# GH 7199 | ||
if obj.ndim < current_ndim: | ||
|
||
# GH 7516 | ||
# if had a 3 dim and are going to a 2d | ||
# axes are reversed on a DataFrame | ||
if i >= 1 and current_ndim == 3 and obj.ndim == 2: | ||
obj = obj.T | ||
|
||
axis -= 1 | ||
|
||
return obj | ||
|
@@ -1559,8 +1483,8 @@ class _LocIndexer(_LocationIndexer): | |
|
||
- A boolean array of the same length as the axis being sliced, | ||
e.g. ``[True, False, True]``. | ||
- A ``callable`` function with one argument (the calling Series, DataFrame | ||
or Panel) and that returns valid output for indexing (one of the above) | ||
- A ``callable`` function with one argument (the calling Series or | ||
DataFrame) and that returns valid output for indexing (one of the above) | ||
|
||
See more at :ref:`Selection by Label <indexing.label>` | ||
|
||
|
@@ -1929,8 +1853,8 @@ class _iLocIndexer(_LocationIndexer): | |
- A list or array of integers, e.g. ``[4, 3, 0]``. | ||
- A slice object with ints, e.g. ``1:7``. | ||
- A boolean array. | ||
- A ``callable`` function with one argument (the calling Series, DataFrame | ||
or Panel) and that returns valid output for indexing (one of the above). | ||
- A ``callable`` function with one argument (the calling Series or | ||
DataFrame) and that returns valid output for indexing (one of the above). | ||
This is useful in method chains, when you don't have a reference to the | ||
calling object, but would like to base your selection on some value. | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this ever raised in user code? what happens when a 3-d indexer is passed?
There was a problem hiding this 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 sort of test for this (also this should raise a ValueError if its user code)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added some tests for 3d indexing (integer ndarray only at the moment). not sure if this was what was required. tests is messy with mixture of some getting and setting not raising and those that raise produce a range of error messages.
will look into this next.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since NDFrame is not part of the API, i'm not sure how this can be raised from user code. (other than Panel)
i've added a test for NDFrame initialized with 3d array, but it only raises this exception with
.ix