-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: add tests for DatetimeIndex.is_year_start/is_quarter_start on "BMS" frequency #58691
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
TST: add tests for DatetimeIndex.is_year_start/is_quarter_start on "BMS" frequency #58691
Conversation
natmokval
commented
May 12, 2024
•
edited
Loading
edited
- closes BUG: DatetimeIndex.is_year_start breaks on BusinessMonthBegin frequency #58729
- Tests added and passed
- Added an entry in the latest `doc/source/whatsnew/v3.0.0.rst
Thanks @natmokval for the PR. Should the OP be an issue instead.? or is there already an open issue for this? |
thanks @simonjayhawkins for the comment. No, there is no open issue for this. |
…eq-BusinessMonthStart
Fixed bug in |
thanks for looking into this not sure this fixes the issue to be honest: In [2]: pd.DatetimeIndex(['1976-11-01', '1976-12-01', '1977-01-03'], freq='BMS')
Out[2]: DatetimeIndex(['1976-11-01', '1976-12-01', '1977-01-03'], dtype='datetime64[s]', freq='BMS')
In [3]: arr = pd.DatetimeIndex(['1976-11-01', '1976-12-01', '1977-01-03'], freq='BMS')
In [4]: arr.is_year_start
Out[4]: array([False, False, True])
In [5]: [x.is_year_start for x in arr]
Out[5]: [False, False, False] We'd expect Here's a little hypothesis test I put together: import pytest
import hypothesis.strategies as st
from hypothesis import given
import pandas as pd
from datetime import datetime
@pytest.mark.parametrize('freq', [
'MS',
'BMS',
])
@given(dt = st.datetimes(min_value=datetime(1960, 1, 1), max_value=datetime(1980, 1, 1)))
def test_me(freq, dt):
d = pd.date_range(dt, periods=3, freq=freq)
result = [x for x in d.is_year_start]
expected = [x.is_year_start for x in d]
assert result == expected Granted, it looks like this is already super-broken on |
Sorry, as an addendum to my previous comment: If I amend the hypothesis test to be: @given(
dt = st.datetimes(min_value=datetime(1960, 1, 1), max_value=datetime(1980, 1, 1)),
n = st.integers(min_value=1, max_value=10),
freq = st.sampled_from(['BMS'])
)
def test_me(freq, dt, n):
freq = f'{n}{freq}'
d = pd.date_range(dt, periods=3, freq=freq)
result = [x for x in d.is_year_start]
expected = []
for x in d:
if x.is_year_start:
expected.append(True)
else:
if x.day_of_week == 0 and (x - pd.Timedelta(days=1)).is_year_start:
expected.append(True)
elif x.day_of_week == 0 and (x - pd.Timedelta(days=2)).is_year_start:
expected.append(True)
else:
expected.append(False)
assert result == expected then it does indeed pass I think we should get #57494 in first though, as I think that that also fixes the issues "for free" (but then we keep the test from this one) |
…req_business_month_begin
@MarcoGorelli, I updated this PR, could you please take a look at my changes? |
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.
thanks @natmokval !