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

mroeschke opened this issue Feb 25, 2018 · 1 comment


None yet
3 participants
Copy link

commented Feb 25, 2018

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

In [2]: s
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
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 this to the 0.23.0 milestone Feb 25, 2018


This comment has been minimized.

Copy link

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
You can’t perform that action at this time.