-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: allow non-Tick offsets in index.round/ceil/floor #27090
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
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'm a little weary of adding rounding for exotic, non-fixed offsets with the potential ambiguity in behavior.
To begin, if you could create a table with a dummy example and the rounding behavior for the offests contained in this section, that'd help flesh out some potential edge cases:
https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#dateoffset-objects
Is that reasonable? is the code ok? |
Okay for |
see also #27098, implementing .round() would also be ok for non-Tick based offsets using something like the current implementation of .snap() |
ok, good, i'll get it together. As for round, I'm unclear. AFAICT, snap does exactly what we were concerned round shouldn't do. |
To copy here, the suggested idiom is: dr.to_period('MS').to_timestamp(how='end') I switched to that and added tests. There are two problems:
import pandas as pd
from pandas._libs.tslibs import frequencies as libfrequencies
pi=pd.period_range("2001-01-01",periods=3,freq="MS")
dti=pi.to_timestamp(how='start')
pandas/core/arrays/period.py in _get_ordinal_range(start, end, periods, freq, mult)
883
884 if freq is not None:
--> 885 _, mult = libfrequencies.get_freq_code(freq)
ValueError: Invalid frequency: MS
In [26]: import pandas as pd
...: from pandas._libs.tslibs import frequencies as libfrequencies
...: dti=pd.DatetimeIndex(["2001-02-01"])
...: print(dti)
...: dti.to_period('M').to_timestamp(how='start')
DatetimeIndex(['2001-02-01'], dtype='datetime64[ns]', freq=None)
Out[26]: DatetimeIndex(['2001-02-01'], dtype='datetime64[ns]', freq=None) I think that result is what |
The approach I originally suggested was rejected (and had issues). The alternative you suggested doesn't work out. Some guidance, please? A User wanted this two years ago and it stalled because they needed feedback and didn't get it. It'd be a shame for that to happen a second time. |
I'd like to complete this, but I'm stuck without an answer. My approach was rejected, and the one suggested hit a wall. I'm wary of investing time in another approach only to have it rejected again. |
ping. |
I really wanted to get this working but it's been ignored enough to make me give up on it. |
related #27087 (Add
DayBegin
,DayEnd
offsets)git diff upstream/master -u -- "*.py" | flake8 --diff
I ran into #15303
This comment argues that implementing
round()
doesn't make sense here, since with non-fixed offsets it might round some midpoints up and some down. That might be what the user actually wants, but it's a subtle point. I put the commented code in anyway, just as an option, and implemented dti.floor
/ceil
.If there's intent-to-merge, I'll add the tests etc'.