Skip to content

Conversation

@bilaljai
Copy link

@bilaljai bilaljai commented Dec 11, 2022

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.

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.
@bilaljai bilaljai changed the title BUG: Bug fix for issue #49925 BUG: fixed issue where Index was being accessed with DatetimeIndex attribute Dec 11, 2022
Copy link
Member

@phofl phofl left a 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

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In previous versions, an error occured if the :meth:`dates` method is ran for a date range
Copy link
Member

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

Copy link
Author

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.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In previous versions, an error occurred if the :meth:`dates` method is ran for a date range.
Copy link
Member

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

Copy link
Author

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

Copy link
Author

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"))
Copy link
Member

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

Copy link
Author

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.

@mroeschke mroeschke added Frequency DateOffsets Index Related to the Index class or subclasses labels Dec 13, 2022
@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot added the Stale label Jan 13, 2023
- 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`)
Copy link
Member

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

@mroeschke
Copy link
Member

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.

@mroeschke mroeschke closed this Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Frequency DateOffsets Index Related to the Index class or subclasses Stale

4 participants