-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
API: Deprecate renamae_axis and reindex_axis #17842
API: Deprecate renamae_axis and reindex_axis #17842
Conversation
Hmm, looks like I'll have to give |
This sets us up to re-use it for Panel reindex
I really wouldn't bother with that. Panel is deprecated, and IMO there is no need in making Panel's functions consistent. |
I wish I had that option :) It seems to be unavoidable though since some generic methods used I have it working for Panel. Working on Panel4D now, hopefully not much longer. |
We're getting the refactoring of |
Another option is to just make a |
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.
some doc comments
doc/source/whatsnew/v0.21.0.txt
Outdated
@@ -810,6 +810,8 @@ Deprecations | |||
- ``.get_value`` and ``.set_value`` on ``Series``, ``DataFrame``, ``Panel``, ``SparseSeries``, and ``SparseDataFrame`` are deprecated in favor of using ``.iat[]`` or ``.at[]`` accessors (:issue:`15269`) | |||
- Passing a non-existent column in ``.to_excel(..., columns=)`` is deprecated and will raise a ``KeyError`` in the future (:issue:`17295`) | |||
- ``raise_on_error`` parameter to :func:`Series.where`, :func:`Series.mask`, :func:`DataFrame.where`, :func:`DataFrame.mask` is deprecated, in favor of ``errors=`` (:issue:`14968`) | |||
- Using :meth:`DataFrame.rename_axis` and :meth:`Series.rename_axis` to alter index or column *labels* is now deprecated in favor of using ``.rename``. ``rename_axis`` may still be used to alter the name of the index or columns (:issue:`17833`). | |||
- :meth:`~NDFrame.reindex_axis` has been deprecated in favor of :meth:`~NDFrame.reindex`. See :ref`here` <whatsnew_0210.enhancements.rename_reindex_axis> for more (:issue:`17833`). |
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.
'NDFrame' is not something that exists in the documentation. You can just use DataFrame
(it will not be shown because of the ~
, and the docstrings are the same for series/dataframe)
pandas/core/computation/align.py
Outdated
@@ -89,6 +89,7 @@ def _align_core(terms): | |||
for axis, items in zip(range(ndim), axes): | |||
ti = terms[i].value | |||
|
|||
# TODO: handle this for when reindex_axis is removed... | |||
if hasattr(ti, 'reindex_axis'): |
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.
and using 'reindex' instead of 'reindex_axis' is not good enough?
pandas/core/generic.py
Outdated
the axis *labels* by passing a mapping or scalar. This behavior is | ||
deprecated and will be removed in a future version. Use ``rename`` | ||
instead. | ||
|
||
See Also | ||
-------- | ||
pandas.NDFrame.rename |
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.
sidenote: this is useless (does not make a link). Unless you want to start with shared docstring/substitution, I would just explicitly add both for series/frame: pandas.Series.rename, pandas.DataFrame.rename
axes = self._validate_axis_style_args( | ||
labels, 'labels', axes=[items, major_axis, minor_axis], | ||
axis=axis, method_name='reindex') | ||
if self.ndim >= 4: |
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.
I got a bit annoyed with PanelND :) I think this is acceptable until we remove it.
@@ -116,7 +116,9 @@ def test_pivot_table_dropna_categoricals(self): | |||
|
|||
result_false = df.pivot_table(index='B', columns='A', values='C', | |||
dropna=False) | |||
expected_columns = Series(['a', 'b', 'c', 'd'], name='A') | |||
expected_columns = ( |
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.
I wanted to flag this change in the tests. AFAICT, this is actually the desired behavior? Looking for issues about this now.
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.
The support for Panel(nd) makes it much less readable .., but since you already did the hard work, it's ok for me :-)
Added some more comments.
pandas/core/generic.py
Outdated
axis = self._get_axis_name(axis) | ||
if any(x is not None for x in axes): | ||
msg = ( | ||
"Can't specify both 'axis' and {aliases}" |
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.
add ". " at the end of this string? (point + space)
pandas/core/groupby.py
Outdated
@@ -4580,7 +4580,7 @@ def _get_sorted_data(self): | |||
|
|||
# this is sort of wasteful but... | |||
sorted_axis = data.axes[self.axis].take(self.sort_idx) | |||
sorted_data = data.reindex(sorted_axis, axis=self.axis) | |||
sorted_data = data.reindex_axis(sorted_axis, axis=self.axis) |
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.
This won't cause a deprecation warning in our own 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.
data
here is a BlockManager (I incorrectly changed this in an earlier commit)
pandas/core/generic.py
Outdated
|
||
elif _all_not_none(arg, *axes): | ||
msg = ( | ||
"Cannot specify all of '{arg_name}', {aliases}" |
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.
also missing ". "
pandas/core/generic.py
Outdated
"Can't specify both 'axis' and {aliases}" | ||
"Specify either\n" | ||
"\t.{method_name}({arg_name}, axis=axis), or\n" | ||
"\t.{method_name}(index=index, columns=columns)" # TODO |
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.
does your 'todo' point to the fact that "index=index, columns=columns" is not generic for all NDFrame types ? (like Panels) If that is the case, I personally wouldn't care.
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.
Yep, I'll happily ignore :)
expected_columns = Series(['a', 'b', 'c', 'd'], name='A') | ||
expected_columns = ( | ||
Series(['a', 'b', 'c', 'd'], name='A').astype('category') | ||
) |
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.
how is this change related?
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.
Not sure :) The fact that it's only not a CategoricalIndex when in the columns and dropna=True seems like a bug on master.
# This is on master
In [7]: df.pivot_table(index="B", columns="A", values="C", dropna=False).columns
Out[7]: Index(['a', 'b', 'c', 'd'], dtype='object', name='A')
In [8]: df.pivot_table(index="A", columns="B", values="C", dropna=False).index
Out[8]: CategoricalIndex(['a', 'b', 'c', 'd'], categories=['a', 'b', 'c', 'd'], ordered=False, name='A', dtype='category')
I've added a whatsnew.
Codecov Report
@@ Coverage Diff @@
## master #17842 +/- ##
==========================================
- Coverage 91.22% 91.21% -0.02%
==========================================
Files 163 163
Lines 50014 50033 +19
==========================================
+ Hits 45627 45637 +10
- Misses 4387 4396 +9
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #17842 +/- ##
==========================================
- Coverage 91.22% 91.21% -0.02%
==========================================
Files 163 163
Lines 50014 50033 +19
==========================================
+ Hits 45627 45637 +10
- Misses 4387 4396 +9
Continue to review full report at Codecov.
|
https://travis-ci.org/pandas-dev/pandas/jobs/287943551 @TomAugspurger some deprecation warnings still in test_panel I think. can you fix. |
* API: Deprecate renamae_axis and reindex_axis Closes pandas-dev#17833 * REF: Refactor axis style validator to generic This sets us up to re-use it for Panel reindex * fixup! API: Deprecate renamae_axis and reindex_axis * fixup! API: Deprecate renamae_axis and reindex_axis * fixup! API: Deprecate renamae_axis and reindex_axis * fixup! API: Deprecate renamae_axis and reindex_axis * Ugh * fixup! API: Deprecate renamae_axis and reindex_axis * Fixup
* API: Deprecate renamae_axis and reindex_axis Closes pandas-dev#17833 * REF: Refactor axis style validator to generic This sets us up to re-use it for Panel reindex * fixup! API: Deprecate renamae_axis and reindex_axis * fixup! API: Deprecate renamae_axis and reindex_axis * fixup! API: Deprecate renamae_axis and reindex_axis * fixup! API: Deprecate renamae_axis and reindex_axis * Ugh * fixup! API: Deprecate renamae_axis and reindex_axis * Fixup
* API: Deprecate renamae_axis and reindex_axis Closes pandas-dev#17833 * REF: Refactor axis style validator to generic This sets us up to re-use it for Panel reindex * fixup! API: Deprecate renamae_axis and reindex_axis * fixup! API: Deprecate renamae_axis and reindex_axis * fixup! API: Deprecate renamae_axis and reindex_axis * fixup! API: Deprecate renamae_axis and reindex_axis * Ugh * fixup! API: Deprecate renamae_axis and reindex_axis * Fixup
Closes #17833
Some notes:
rename_axis
ismapper
, which isn't really descriptive of what it does now. Oh well