-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
ENH: partial string indexing on non-monotonic PeriodIndex #31096
ENH: partial string indexing on non-monotonic PeriodIndex #31096
Conversation
Is this a bug fix or a new feature? Can you add a whatsnew? |
…h-pi-slice-nonmonotonic
I think it counts as a feature, but there are a lot of inconsistencies in the surrounding code, so I wouldn't argue the point. Just added whatsnew. |
|
||
Nonmonotonic PeriodIndex Partial String Slicing | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
:class:`PeriodIndex` now supports partial string slicing for non-monotonic indexes, mirroring :class:`DatetimeIndex` behavior (:issue:`31096`) |
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 update the docs: https://pandas.io/docs/user_guide/timeseries.html#partial-string-indexing
.. ipython:: python | ||
|
||
dti = pd.date_range("2014-01-01", periods=30, freq="30D") | ||
pi = dti.to_period("D") |
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 show ser, maybe break this into 2 to make it more readable
…h-pi-slice-nonmonotonic
can you rebase |
…h-pi-slice-nonmonotonic
doc/source/user_guide/timeseries.rst
Outdated
@@ -1981,6 +1981,9 @@ As with ``DatetimeIndex``, the endpoints will be included in the result. The exa | |||
|
|||
dfp['2013-01-01 10H':'2013-01-01 11H'] | |||
|
|||
As of version 1.1.0, this works with non-monotonic ``PeriodIndex`` indexes. |
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, should be versionadded directive. (ad put at the beginning of the slicing with period strings section); thought we didn't have any docs on this (but seems we do)
ser = ser_monotonic[shuffler] | ||
ser | ||
|
||
ser["2014"] |
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 make a separate ipythonblock for these last 2
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.
doc comments, otherwise lgtm.
one more rebase |
…h-pi-slice-nonmonotonic
rebased+green |
Thanks @jbrockmendel |
Looks like the DatetimeIndex analogue of this was done in #2437 (3a173f1)
This does not yet support two-sides slicing e.g.
ser["2015":"2016"]
, but im hoping to get that handled before long.Partial overlap with #31058, nothing should actually conflict.