-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DEPR: Deprecate the convert parameter completely #17831
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
DEPR: Deprecate the convert parameter completely #17831
Conversation
d5337d1
to
1080c19
Compare
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.
Thanks! Left a few comments, in general IMO it is not needed to explain this for the user, for them the default is still True
pandas/core/generic.py
Outdated
@@ -2135,13 +2135,18 @@ def _take(self, indices, axis=0, convert=True, is_copy=True): | |||
axis : int, default 0 | |||
The axis on which to select elements. "0" means that we are | |||
selecting rows, "1" means that we are selecting columns, etc. | |||
convert : bool, default True |
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.
You can leave this as True
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.
Ok, will fix.
pandas/core/generic.py
Outdated
|
||
Whether to convert negative indices into positive ones. | ||
For example, ``-1`` would map to the ``len(axis) - 1``. | ||
The conversions are similar to the behavior of indexing a | ||
regular Python list. | ||
|
||
If ``None`` is passed in, negative indices will be converted | ||
to positive indices. |
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 is not needed IMO
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.
Ok, will fix.
@@ -856,6 +856,10 @@ def test_take(self): | |||
result = df.take(order, convert=False, axis=0) | |||
assert_frame_equal(result, expected) | |||
|
|||
with tm.assert_produces_warning(FutureWarning): | |||
result = df.take(order, convert=False, axis=0) |
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.
Should this be True?
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, it should. Oops 😄
sp.take([1, 5], convert=False) | ||
|
||
def test_numpy_take(self): | ||
sp = SparseSeries([1.0, 2.0, 3.0]) | ||
indices = [1, 2] | ||
|
||
# gh-17352: older versions of numpy don't properly | ||
# pass in arguments to downstream .take() implementations. | ||
warning = FutureWarning if _np_version_under1p12 else None |
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 there a reason this is not the case anymore?
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.
Actually, I need to put that back. However, I different default will be needed, as convert=None
breaks downstream compatibility with numpy
:
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.
What is the problem with None for numpy? You linked to a sparse failure, but in the sparse code you left the default as None.
If it is needed, another solution might be to push it into the kwargs? (so the -1 is not visible)
BTW, can you push new commits instead of squashing into the previous one? That makes it easier to say what you changed.
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.
Oh, sorry, missed your message before I pushed.
The problem is that numpy
's take
implementation for slightly older versions passes in None
for one of its parameters by position. This parameter corresponds to the convert
parameter for our version of take
. It's messy compatibility stuff that I had to wade through at some point that I patched on both sides.
2f2db4f
to
c5d0f08
Compare
The new kwarg gets past the original failure but need a more robust comparator. |
pandas/core/generic.py
Outdated
nv.validate_take(tuple(), kwargs) | ||
|
||
if not convert: | ||
def take(self, indices, axis=0, convert=-1, is_copy=True, **kwargs): |
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.
why can’t u just use None
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.
@jreback : breaks compatibility with older numpy versions
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 how, you are stripping the kwarg before passing it on
pandas/core/sparse/series.py
Outdated
convert = nv.validate_take_with_convert(convert, args, kwargs) | ||
|
||
if not convert: | ||
def take(self, indices, axis=0, convert=-1, *args, **kwargs): |
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.
same this is very non intuitive to use a placeholder value that is not valid
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.
Well, none is not a valid parameter for a boolean input either, and the compatibility issue still stands
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.
sure it is, you need to set the default before you check the inputs. That's the point.
if convert is not None:
warnings.warn(.....)
validate(convert)
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.
@jreback : I do set the default beforehand, and everything is green now.
c5d0f08
to
762fd6e
Compare
Codecov Report
@@ Coverage Diff @@
## master #17831 +/- ##
==========================================
+ Coverage 91.22% 91.22% +<.01%
==========================================
Files 163 163
Lines 50014 50016 +2
==========================================
+ Hits 45627 45629 +2
Misses 4387 4387
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #17831 +/- ##
==========================================
- Coverage 91.25% 91.2% -0.05%
==========================================
Files 163 163
Lines 50038 50040 +2
==========================================
- Hits 45661 45638 -23
- Misses 4377 4402 +25
Continue to review full report at Codecov.
|
Everything is passing. PTAL. |
Can I please unsubscribe
On Tue, Oct 10, 2017 at 7:11 AM gfyoung ***@***.***> wrote:
Previously, we weren't issuing a warning if the user happened to pass in
the original default of True,
which would cause downstream code to break.
Closes #17828 <#17828>
------------------------------
You can view, comment on, or merge this pull request online at:
#17831
Commit Summary
- DEPR: Deprecate the convert parameter completely
File Changes
- *M* pandas/compat/numpy/function.py
<https://github.com/pandas-dev/pandas/pull/17831/files#diff-0> (6)
- *M* pandas/core/generic.py
<https://github.com/pandas-dev/pandas/pull/17831/files#diff-1> (13)
- *M* pandas/core/sparse/series.py
<https://github.com/pandas-dev/pandas/pull/17831/files#diff-2> (8)
- *M* pandas/tests/frame/test_axis_select_reindex.py
<https://github.com/pandas-dev/pandas/pull/17831/files#diff-3> (4)
- *M* pandas/tests/sparse/test_series.py
<https://github.com/pandas-dev/pandas/pull/17831/files#diff-4> (14)
Patch Links:
- https://github.com/pandas-dev/pandas/pull/17831.patch
- https://github.com/pandas-dev/pandas/pull/17831.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#17831>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJfa3Nd7QUQ4eegHECsoBwQ54cWa-D2ks5sqvxrgaJpZM4PzYie>
.
--
Greg Gurevich
[email protected]
cell: 1-917-504-7105
|
@bkmrkr If you scroll above, there is a button 'Unwatch' (or watch), if you click on the dropdown, you can choose which issue to follow. |
Thoughts @jreback? This is blocking the RC now. @gfyoung could you explain in a bit more detail why making def take(self, indices, axis=0, convert=None, is_copy=True, **kwargs):
if convert is None:
convert = True
else:
warnings.warn(...) would work fine. Not a huge deal, just a little strange to use -1 instead of None I think. |
@TomAugspurger : I've tried various logic (including that one), and older versions of If we were to drop support for |
@gfyoung I think let's keep the signature with |
not goning to happen :> (actually you can leave the test for >= 1.12 for this as it will work with |
Okay, will do.
Oh, that's too bad. I thought there was a good chance we would do that 😄 |
5ac5e38
to
29b6b64
Compare
Previously, we weren't issuing a warning if the user happened to pass in the original default of "True", which would cause downstream code to break. Closes pandas-devgh-17828.
29b6b64
to
8f946b7
Compare
Finally, all is green again. PTAL. |
@@ -2172,6 +2172,7 @@ def _take(self, indices, axis=0, convert=True, is_copy=True): | |||
selecting rows, "1" means that we are selecting columns, etc. | |||
convert : bool, default True | |||
.. deprecated:: 0.21.0 | |||
In the future, negative indices will always be converted. |
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.
leftover comment
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.
@TomAugspurger prob just as easy to fix this on merge
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 can fix that in #17858
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.
Although, why do you say that's leftover? Wasn't that added deliberately @gfyoung?
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.
Yes
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.
actually nvm thought was a different comment
lgtm module a small doc comment.. |
Previously, we weren't issuing a warning if the user happened to pass in the original default of "True", which would cause downstream code to break. Closes pandas-devgh-17828.
* upstream/master: (76 commits) CategoricalDtype construction: actually use fastpath (pandas-dev#17891) DEPR: Deprecate tupleize_cols in to_csv (pandas-dev#17877) BUG: Fix wrong column selection in drop_duplicates when duplicate column names (pandas-dev#17879) DOC: Adding examples to update docstring (pandas-dev#16812) (pandas-dev#17859) TST: Skip if no openpyxl in test_excel (pandas-dev#17883) TST: Catch read_html slow test warning (pandas-dev#17874) flake8 cleanup (pandas-dev#17873) TST: remove moar warnings (pandas-dev#17872) ENH: tolerance now takes list-like argument for reindex and get_indexer. (pandas-dev#17367) ERR: Raise ValueError when week is passed in to_datetime format witho… (pandas-dev#17819) TST: remove some deprecation warnings (pandas-dev#17870) Refactor index-as-string groupby tests and fix spurious warning (Bug 17383) (pandas-dev#17843) BUG: merging with a boolean/int categorical column (pandas-dev#17841) DEPR: Deprecate read_csv arguments fully (pandas-dev#17865) BUG: to_json - prevent various segfault conditions (GH14256) (pandas-dev#17857) CLN: Use pandas.core.common for None checks (pandas-dev#17816) BUG: set tz on DTI from fixed format HDFStore (pandas-dev#17844) RLS: v0.21.0rc1 Whatsnew cleanup (pandas-dev#17858) DEPR: Deprecate the convert parameter completely (pandas-dev#17831) ...
Previously, we weren't issuing a warning if the user happened to pass in the original default of "True", which would cause downstream code to break. Closes pandas-devgh-17828.
Previously, we weren't issuing a warning if the user happened to pass in the original default of "True", which would cause downstream code to break. Closes pandas-devgh-17828.
Previously, we weren't issuing a warning if the user happened to pass in the original default of
True
,which would cause downstream code to break.
Closes #17828