You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We would like to learn about your use case. For example, if this feature is needed to adopt Narwhals in an open source project, could you please enter the link to it below?
No response
Please describe the purpose of the new feature or describe the problem to solve.
It would be nice to have a method to subtract and add periods from date and datetime columns. My use case for this is calculating year over year change by self joining a dataframe on month = previous year month. However, there are many other use cases for this when working with timeseries data.
Suggest a solution if possible.
No response
If you have tried alternatives, please describe them below.
I couldn't find a good alternative.
Additional information that may help us understand your needs.
No response
Reacted by Dan Redding, Marco Edward Gorelli and Jason Rosenfeld
we should definitely add this, but with the same restriction that we have in dt.truncate, that is to say: that we accept durations of the form , and not combinations of them. E.g.:
Activity
MarcoGorelli commentedon May 18, 2025
thanks @denisdlugach for the request!
we should definitely add this, but with the same restriction that we have in
dt.truncate, that is to say: that we accept durations of the form , and not combinations of them. E.g.:dt.offset_by('1mo')is validdt.offset_by('1mo2d3h')is notdangotbanned commentedon May 18, 2025
Agreed #2573 (comment)
MarcoGorelli commentedon May 19, 2025
Another important note:
'1d'should behave like one calendar day, not like'24h'.Fortunately, duckdb and Polars do this by default:
but for pandas, IIRC, the behaviour changes between version 2 and 3. We'd need to find a way to make sure we're always adding 1 calendar day
camriddell commentedon May 19, 2025
@MarcoGorelli would
pandas.tseries.offsetsbe stable across versions for this behavior? (e.g. pandas.tseries.offsets.Day).MarcoGorelli commentedon May 19, 2025
nope 😭
MarcoGorelli commentedon Jun 23, 2025
what you could do for pandas, though, is:
dt.tz_localize(None))pandas.tseries.offsets.Daydt.tz_localize(original_time_zone))i think that should work?
raisadz commentedon Jun 25, 2025
I started working on it, will try to put some draft soon
denisdlugach commentedon Jul 9, 2025
@raisadz @MarcoGorelli was there plan to support negative offsets? Eg. "-12mo"?
raisadz commentedon Jul 14, 2025
Thanks for the request @denisdlugach , I am working on a PR to add negative offsets