-
- Notifications
You must be signed in to change notification settings - Fork 19.4k
BUG: fixed issue where Index was being accessed with DatetimeIndex attribute #50179
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
Conversation
Added a check in the dates method to address the bug mentioned in issue pandas-dev#49925. If the dates method is ran for a date range outside of the holiday's start_date/end_date the holiday_dates object is converted from Index to DateTimeIndex and daysofweek is no longer invoked on an Index object.
Added test case to ensure that the return type of the dates method is DateTimeIndex even when the holiday provided is outside of the date range provided.
Added entry for notable bug fixes to document change to the dates method in pandas/tseries/holiday.py
Fixed display for new entry in notable bug fixes.
phofl left a comment
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.
Can you run pre-commit? Your formatting is off
doc/source/whatsnew/v2.0.0.rst Outdated
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
| In previous versions, an error occured if the :meth:`dates` method is ran for a date range |
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.
A short note is sufficient here. This is a pretty small change
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 for the feedback I've ran pre-commit and updated v2.0.0.rst to include your suggestion.
Added author's suggestion for a small not about DatetimeIndex bug fix.
Fixed type on new bug fix entry.
doc/source/whatsnew/v2.0.0.rst Outdated
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
| In previous versions, an error occurred if the :meth:`dates` method is ran for a date range. |
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.
You can just add this to one of the bug fixes sections below
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.
Ah I see I'll work on it now
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.
I've added this to the Timezones section.
| | ||
| def test_holidays_outside_dates(): | ||
| hol = Holiday("Dec 25", month=12, day=25, observance=next_monday, days_of_week=(5, 6), | ||
| end_date=Timestamp("2013-01-01")) |
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.
The formatting is off, pre-commit should fix this
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.
Ran pre-commit, formatting fixed now.
| This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this. |
| - Bug in :meth:`Series.astype` and :meth:`DataFrame.astype` with object-dtype containing multiple timezone-aware ``datetime`` objects with heterogeneous timezones to a :class:`DatetimeTZDtype` incorrectly raising (:issue:`32581`) | ||
| - Bug in :func:`to_datetime` was failing to parse date strings with timezone name when ``format`` was specified with ``%Z`` (:issue:`49748`) | ||
| - | ||
| - Bug in :meth:`dates` was trying to access an DatetimeIndex attribute on an Index object when holiday landed outside of date range provided (:issue:`49925`) |
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.
can you write out the full class.method name, otherwise not clear what "dates" refers to
| Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen. |
start_date/end_dateraises AttributeError when Holiday hasobservanceanddays_of_week#49925doc/source/whatsnew/vX.X.X.rstfile if fixing a bug or adding a new feature.Changes: updated the dates method in pandas/tseries/holiday.py to include a check to prevent the DatetimeIndex attribute
from being accessed by an Index object. The bug occurs if the holidays land outside the provided date range which results in an empty DatetimeIndex object being converted to an Index object. The updated dates method now checks if the object contains elements before allowing access to a DatetimeIndex attribute because such an object will be of type Index. Furthermore, the Index object is converted back into a DatetimeIndex object. A test was added to pandas/tests/tseries/holiday/test_holiday.py to ensure that the intended behavior is occurring.