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: cut return bins should be Timestamp/Timedelta objects for datelike data #19891

Closed
mroeschke opened this issue Feb 25, 2018 · 1 comment · Fixed by #20956
Closed

ENH: cut return bins should be Timestamp/Timedelta objects for datelike data #19891

mroeschke opened this issue Feb 25, 2018 · 1 comment · Fixed by #20956
Labels
Datetime Datetime data dtype Reshaping Concat, Merge/Join, Stack/Unstack, Explode Timezones Timezone data dtype
Milestone

Comments

@mroeschke
Copy link
Member

In [1]: s = pd.Series(pd.date_range('20180101', periods=3))

In [2]: s
Out[2]:
0   2018-01-01
1   2018-01-02
2   2018-01-03
dtype: datetime64[ns]

In [3]: res, bins = pd.cut(s, 2, retbins=True)

In [4]: pd.cut(s, bins)  # Bins do not "roundtrip"

ValueError: bins must be of datetime64 dtype

In [5]: pd.cut(s, [pd.Timestamp(b) for b in bins]) == res
Out[5]:
0    True
1    True
2    True
dtype: bool

For convenience and argument of "roundtripping", I think cut(..., retbins=True) with datelike data (datetime or timedelta data) should return bins that is an array of Timestamp/Timedelta objects instead of an array of integers.

@jreback jreback added Datetime Datetime data dtype Reshaping Concat, Merge/Join, Stack/Unstack, Explode Timezones Timezone data dtype labels Feb 25, 2018
@jreback jreback added this to the 0.23.0 milestone Feb 25, 2018
@jreback
Copy link
Contributor

jreback commented Feb 25, 2018

related to #19872

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Reshaping Concat, Merge/Join, Stack/Unstack, Explode Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants