-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG: date_range
with freq="C"
(business days) return value changed on 1.5.0
#49441
Comments
Thanks for the report. I'm seeing the same on main. From a quick look, #48385 touched the related code path most recently but the core logic didn't seem to change. cc @jbrockmendel This looks to be the root cause of the behavior
|
@mroeschke I would like to contribute to this issue, but I believe that I will require some support as it is my first contribution to pandas. I did a I reverted the modification, only in these lines, and it worked. I need a better understanding of what is happing and figure out how to write a test case for it. One possible solution is just to revert does lines, but I think we are looking for a better solution :) I will continue studying the code to propose a good solution. |
Thanks for investigating @lohmanndouglas. Since this is a regression, it would be valid to revert those line if it fixes this issue and doesn't fail any existing test. A test should be included in |
Thanks @mroeschke I will do it and open a PR as soon as possible :) |
take |
Yes it looks good to me indeed. |
@lohmanndouglas while git bisect points to that commit, IMO the "root" issue still points to the behavior of #49441 (comment), namely why in
|
@mroeschke I did not open the PR because I would like to get a deep understanding of what is happening. We might have changed the function From the following snippet paris = pytz.timezone("Europe/Paris")
start = dt.datetime.fromisoformat("2022-07-22 22:00:00+00:00").astimezone(paris)
print(pd.date_range(start, periods=1, freq="C")) I got in
Knowing that we have two different execution flows in the FLOW 1: Before the #47019 if start and not offset.is_on_offset(start):
# Incompatible types in assignment (expression has type "datetime",
# variable has type "Optional[Timestamp]")
start = offset.rollforward(start) # type: ignore[assignment] The Then, we set the Finally, we check: cur = start
if offset.n >= 0:
while cur <= end:
yield cur
if cur == end:
# GH#24252 avoid overflows by not performing the addition
# in offset.apply unless we have to
break
... As the cur == end is True we just return the solution. In this flow (before #47019) it does not pass through the apply function. FLOW 2: After the #47019After #47019, the Then we also set the Finally, we start the while to find out the periods. As the start is not equal to the end we call the apply. cur = start
if offset.n >= 0:
while cur <= end:
yield cur
if cur == end:
break
[... omitted code]
next_date = offset._apply(cur)
[... omitted code]
cur = next_date
The apply function returns the correct value So far I have this understanding. We need to certify what should be the correct behavior for the DOING -> Studying the def is_on_offset(self, dt: datetime) -> bool:
if self.normalize and not _is_normalized(dt):
return False
day64 = _to_dt64D(dt)
return np.is_busday(day64, busdaycal=self.calendar) I do not have a deep understanding of this code, this is my first issue, and I am very glad for any help. |
Yeah I think this is the crux of the issue as I think we want the naive wall time (
|
@mroeschke tanks sure, I would like to open the PR :) |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
On Pandas 1.4.4, the above shows:
On Pandas 1.5.1, it shows:
There are no warnings from the previous code.
Expected Behavior
THe same results, unless I have missed something in the release notes (I tried reading all results matching date/time/business, couldn't see anything relevant).
Installed Versions
The text was updated successfully, but these errors were encountered: