Skip to content

BUG: Inconsistent "is_year_start" from DatetimeIndex with freq "MS" #57377

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

Closed
2 of 3 tasks
pforero opened this issue Feb 12, 2024 · 4 comments
Closed
2 of 3 tasks

BUG: Inconsistent "is_year_start" from DatetimeIndex with freq "MS" #57377

pforero opened this issue Feb 12, 2024 · 4 comments
Assignees
Labels
Bug datetime.date stdlib datetime.date support

Comments

@pforero
Copy link

pforero commented Feb 12, 2024

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

import pandas as pd
dr = pd.date_range("2017-12-01", periods=2, freq="MS")
dr_comp = [dt.is_year_start for dt in dr]
dr_attr = dr.is_year_start
assert dr[1].is_year_start
assert dr_comp[1]
assert dr_attr[0]  # Should raise error but doesn't
assert dr_attr[1]  # Raises error but shouldn't

Issue Description

When working with DatetimeIndex with frequency "MS" the attribute "is_year_start" does not obtain the same attribute if you obtain the attribute directly from the DatatimeIndex instead of obtaining directly from each individual value of the DatetimeIndex.

Expected Behavior

I would expect for the same array of attributes independently of if it is obtained from a comprehensive list or as an attibute as shown in the documentation.

https://pandas.pydata.org/docs/reference/api/pandas.DatetimeIndex.is_year_start.html

import pandas as pd
dr = pd.date_range("2017-12-01", periods=2, freq="MS")
dr_comp = [dt.is_year_start for dt in dr]
dr_attr = dr.is_year_start
assert not dr[1].is_year_start
assert dr[1].is_year_start
assert not dr_comp[1]
assert dr_comp[1]
assert not dr_attr[0] 
assert dr_attr[1] 

Installed Versions

INSTALLED VERSIONS

commit : f538741
python : 3.11.6.final.0
python-bits : 64
OS : Linux
OS-release : 3.10.0-1160.95.1.el7.x86_64
Version : #1 SMP Fri Jun 23 08:44:55 EDT 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.0
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.8.2
setuptools : 68.2.2
pip : 23.2.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.16.1
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 2.0.21
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.4
qtpy : None
pyqt5 : None

@pforero pforero added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 12, 2024
@rhshadrach
Copy link
Member

Thanks for the report. Confirmed on main, further investigations and PRs to fix are welcome!

@rhshadrach rhshadrach added datetime.date stdlib datetime.date support and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 15, 2024
@mattheeter
Copy link
Contributor

take

@mattheeter
Copy link
Contributor

mattheeter commented Feb 18, 2024

Upon further inspection, it looks like is_quarter_start with the freq 'MS' is having the same issue

idx = pd.date_range('2017-01-01', periods=6, freq='MS')
idx[idx.is_quarter_start]

This gives the dates 2017-03-01 and 2017-06-01, which are of course not the actual start of quarters

@MarcoGorelli
Copy link
Member

looks like this was already reported earlier: #49606

MarcoGorelli added a commit that referenced this issue Jun 8, 2024
… with freq 'MS' date_range (#57377) (#57494)

* Added some comments to where the bug is occurring

* Potential fix, passed all potentially relevant tests

* Very likely fix

* Reverted ro previous start/end scheme; added tests

* Added fixes to whatsnew doc

* Removed stray comment

* Fixed alphabetical problem in whatsnew

* add parametric test

* fixup

---------

Co-authored-by: Marco Gorelli <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug datetime.date stdlib datetime.date support
Projects
None yet
Development

No branches or pull requests

4 participants