Skip to content

API: offsets.Day is always calendar-day #61985

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

jbrockmendel
Copy link
Member

@jbrockmendel jbrockmendel commented Jul 28, 2025

Alternative to #55502 discussed at last week's dev meeting. This allows TimedeltaIndex.freq to be aDay even though it is not a Tick.

@jbrockmendel jbrockmendel requested a review from mroeschke as a code owner July 29, 2025 16:22
@jbrockmendel
Copy link
Member Author

/home/runner/work/pandas/pandas/doc/source/whatsnew/v3.0.0.rst:345: WARNING: Bullet list ends without a blank line; unexpected unindent. [docutils]

is stumping me. Who is our go-to person for debugging these?

@jbrockmendel
Copy link
Member Author

Still seeing

/home/runner/work/pandas/pandas/doc/source/whatsnew/v3.0.0.rst:345: WARNING: Bullet list ends without a blank line; unexpected unindent. [docutils]

Tried building the docs locally and jinja2 is complaining ValueError: PackageLoader could not find a 'io/formats/templates' directory in the 'pandas' package. so doing some yak-shaving.

@jbrockmendel
Copy link
Member Author

Looks like there was even more whitespace I messed up. It's happy now.

@@ -2763,7 +2768,10 @@ def _adjust_dates_anchored(
if offset is not None:
offset = offset.as_unit(unit)

freq_value = Timedelta(freq).as_unit(unit)._value
if isinstance(freq, Day):
Copy link
Member

Choose a reason for hiding this comment

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

In #41943 I was hoping that if D means calendar day, we wouldn't need to force to be a fixed frequency in resample

Copy link
Member Author

Choose a reason for hiding this comment

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

yah i was hoping for this too but wasn't able to get it working. will give it another try after addressing other comments

Copy link
Member Author

Choose a reason for hiding this comment

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

just double-checked. im pretty sure the place to change the treatment would be in _get_timestamp_range_edges a bit up the call stack. Changing that to have Day cases no longer go down the Tick route breaks test_resample_origin_with_day_freq_on_dst and test_resample_tz_localized2. it wasn't obvious that the "new" behavior was correct in those tests with that change. can you confirm?

Copy link
Member

Choose a reason for hiding this comment

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

im pretty sure the place to change the treatment would be in _get_timestamp_range_edges

That makes sense to me, as I would expect us not to have to special case Day anymore

test_resample_origin_with_day_freq_on_dst and test_resample_tz_localized2.

Mind showing an example of the new behavior based on those tests? I would expect breakage for these tests since D changing to calendar day impacts the results around DST.

Copy link
Member Author

Choose a reason for hiding this comment

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

Based on test_resample_tz_localized2:

idx = date_range("2001-09-20 15:59", "2001-09-20 16:00", freq="min", tz="Australia/Sydney")
s = Series([1, 2], index=idx)
    
result = s.resample("D", closed="right", label="right").mean()
ex_index = date_range("2001-09-21", periods=1, freq="D", tz="Australia/Sydney")
expected = Series([1.5], index=ex_index)
    
tm.assert_series_equal(result, expected)  # Fails with actual result being...

ex_index = pd.date_range("2001-09-20", "2001-09-21", tz="Australia/Sydney", freq="D")
expected = Series([np.nan, 1.5], index=ex_index)

@mroeschke mroeschke added the Frequency DateOffsets label Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frequency DateOffsets
Projects
None yet
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy