Skip to content
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

Merged
merged 11 commits into from
Jan 21, 2020

Conversation

jbrockmendel
Copy link
Member

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.

@WillAyd
Copy link
Member

WillAyd commented Jan 17, 2020

Is this a bug fix or a new feature? Can you add a whatsnew?

@jbrockmendel
Copy link
Member Author

Is this a bug fix or a new feature? Can you add a whatsnew?

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.

@jbrockmendel jbrockmendel added the Indexing Related to indexing on series/frames, not to indexes themselves label Jan 17, 2020

Nonmonotonic PeriodIndex Partial String Slicing
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
:class:`PeriodIndex` now supports partial string slicing for non-monotonic indexes, mirroring :class:`DatetimeIndex` behavior (:issue:`31096`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. ipython:: python

dti = pd.date_range("2014-01-01", periods=30, freq="30D")
pi = dti.to_period("D")
Copy link
Contributor

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

@jreback jreback added this to the 1.1 milestone Jan 18, 2020
@jreback jreback added the Period Period data type label Jan 18, 2020
@jreback
Copy link
Contributor

jreback commented Jan 20, 2020

can you rebase

@@ -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.
Copy link
Contributor

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"]
Copy link
Contributor

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

Copy link
Contributor

@jreback jreback left a 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.

@jreback
Copy link
Contributor

jreback commented Jan 20, 2020

one more rebase

@jbrockmendel
Copy link
Member Author

rebased+green

@WillAyd WillAyd merged commit 4050e4c into pandas-dev:master Jan 21, 2020
@WillAyd
Copy link
Member

WillAyd commented Jan 21, 2020

Thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the enh-pi-slice-nonmonotonic branch January 21, 2020 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants