-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
use range in RangeIndex instead of _start etc. #26581
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
Conversation
pandas/core/indexes/range.py
Outdated
.. deprecated:: 0.25.0 | ||
Use ._range.start or .start instead. | ||
""" | ||
return self._range.start |
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.
Unfortunately, fast_parquet uses _start
etc. which I hadn't predicted, when I started this PR. So this proposes deprecating the attributes _start
, _stop
and _step
, and removing them in 1.0.
This can be bit of a nuisance for downstream maintainers, so don't know if there's opposition to this, but this PR has several benefits as mentioned, so there's a trade-off.
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 think pyarrow uses them as well. IIRC recently had a discussion that they're semi-officially public for advanced users (do you recall that @jorisvandenbossche)
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.
don't recommend ._range.start, just say .start
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 think its ok to deprecate these, the downstream will have to adjust
6763b22
to
d947faa
Compare
Codecov Report
@@ Coverage Diff @@
## master #26581 +/- ##
===========================================
- Coverage 91.84% 41.67% -50.18%
===========================================
Files 174 174
Lines 50644 50625 -19
===========================================
- Hits 46516 21099 -25417
- Misses 4128 29526 +25398
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #26581 +/- ##
==========================================
- Coverage 91.87% 91.87% -0.01%
==========================================
Files 174 174
Lines 50692 50672 -20
==========================================
- Hits 46575 46554 -21
- Misses 4117 4118 +1
Continue to review full report at Codecov.
|
8a0750c
to
93d281d
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.
can you add a test for the deprecations?
pandas/core/indexes/range.py
Outdated
.. deprecated:: 0.25.0 | ||
Use ._range.start or .start instead. | ||
""" | ||
return self._range.start |
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.
don't recommend ._range.start, just say .start
pandas/core/indexes/range.py
Outdated
.. deprecated:: 0.25.0 | ||
Use ._range.start or .start instead. | ||
""" | ||
return self._range.start |
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 think its ok to deprecate these, the downstream will have to adjust
pandas/core/indexes/range.py
Outdated
The value of the `stop` parameter | ||
|
||
.. deprecated:: 0.25.0 | ||
Use ._range.stop or .stop instead. |
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 as above (you don't need to put the issue numbers in the code)
pandas/core/indexes/range.py
Outdated
The value of the `step` parameter (or ``1`` if this was not supplied) | ||
|
||
.. deprecated:: 0.25.0 | ||
Use ._range.step or .step instead. |
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
pandas/core/indexes/range.py
Outdated
|
||
return RangeIndex._simple_new(start, stop, step, name=self.name) | ||
new_range = self._range[key] | ||
return RangeIndex.from_range(new_range, name=self.name) |
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.
are you using cls everywhere? (or self.class)? (can be either just be consistent)
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 wasn't, but I've changed it. For constructor method like this I've done self._from_range(...)
.
also a note in the whatsnew for the deprecation |
93d281d
to
123013c
Compare
Hello @topper-123! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2019-06-04 09:18:53 UTC |
dee54ed
to
f14384c
Compare
lgtm. @TomAugspurger @jorisvandenbossche any objections? |
@WillAyd see comments above, they are using in |
Whoops sorry - thanks for clarifying |
What's the plan on warning? Should we throw a (not visible) DeprecationWarning for now, and promote that to a FutureWarning? Or just add a FutureWarning after pyarrow / fastparquet can update? |
My plan is to just post an issue on the issue lists for EDIT: My cercern for adding a code message was that it would be visible and therefore annoying for users of those packages. I could add a DeprecationWarning, if that one is more quiet than the usual FutureWarning. |
ok let’s do a DeprecationWarning now |
I actually see now that DeprecationWarnings are also displayed by default. I thought they were only shown when starting Python with Uploading anyway now I've done it and there's a demand for the warnings. |
f14384c
to
233aad0
Compare
Only if you directly use the deprecated method or attribute, but they should not show up if you eg call a function that uses them (which should be the case for libraries such as pyarrow / fastparquet). |
Personally, I am -1 on deprecating them (pyarrow/fastparquet only just started to use them, we literally said them it was fine, it's more annoying for them to deal with an attribute name change than for us to just keep it a couple of releases more). But if we're using a deprecation instead of future warning, I won't object if the majority is fine with deprecating. |
right this is the purpose of the DeprecationWarning (rather than FutureWarning) as it won't show-up too much; but the deprecation should happen. |
@topper-123 can you file an issue on fastparquet and a JIRA on pyarrow. |
No problem. I'd like to have this merged before I write the issues, so they can see the issue by just pulling pandas master. |
98d1881
to
228b560
Compare
thanks @topper-123 |
git diff upstream/master -u -- "*.py" | flake8 --diff
Make RangeIndex use python's
range
internally, rather than the three scalars_start
,_stop
and_step
.Python3's
range
has several nice properties, that were not available inxrange
in Python2. For example it's sliceable, and has.index
andcount
methods. These can be used in Pandas, rather than maintaining Pandas-specific code, offering cleaner code and possibly faster operations.