Skip to content

Commit

Permalink
Merge pull request #377 from rsheftel/dev
Browse files Browse the repository at this point in the history
Fix regression error in #376
  • Loading branch information
rsheftel authored Jan 25, 2025
2 parents ef5f21b + ba4b290 commit 47b3f1c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
4 changes: 4 additions & 0 deletions docs/change_log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Change Log

Updates
-------
4.6.1 (01/23/2025)
~~~~~~~~~~~~~~~~~~
- patch to fix the regression error in #376

4.6.0 (01/16/2025)
~~~~~~~~~~~~~~~~~~
- Updated usage.ipynb with information on added features
Expand Down
9 changes: 5 additions & 4 deletions pandas_market_calendars/calendars/nyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@

from datetime import time
from itertools import chain
from typing import Literal, Union

import pandas as pd
from pandas.tseries.holiday import AbstractHolidayCalendar
from pandas.tseries.offsets import CustomBusinessDay
from pytz import timezone

from typing import Literal, Union
from pandas_market_calendars import calendar_utils as u

from pandas_market_calendars.holidays.nyse import (
# Always Celebrated Holidays
USNewYearsDayNYSEpost1952,
Expand Down Expand Up @@ -1306,8 +1305,10 @@ def valid_days(self, start_date, end_date, tz="UTC"):
:param tz: time zone in either string or pytz.timezone
:return: DatetimeIndex of valid business days
"""
start_date = pd.Timestamp(start_date, tz=tz)
end_date = pd.Timestamp(end_date, tz=tz)
start_date = pd.Timestamp(start_date)
end_date = pd.Timestamp(end_date)
start_date = start_date.tz_convert(tz) if start_date.tz else start_date.tz_localize(tz)
end_date = end_date.tz_convert(tz) if end_date.tz else end_date.tz_localize(tz)

# Starting Monday Sept. 29, 1952, no more saturday trading days
if tz is None:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[project]
name = "pandas_market_calendars"
version = "4.6.0"
version = "4.6.1"
authors = [
{ name = "Ryan Sheftel", email = "[email protected]" },
]
description = "Market and exchange trading calendars for pandas"
readme = "README.rst"
requires-python = ">=3.8"
requires-python = ">=3.9"
keywords = ["trading", "exchanges", "markets", "OTC", "datetime", "holiday", "business days"]
license = { text = "MIT" }
classifiers = [
Expand Down
15 changes: 15 additions & 0 deletions tests/test_nyse_calendar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime as dt
import os
from zoneinfo import ZoneInfo

import pandas as pd
import pytest
Expand Down Expand Up @@ -146,6 +147,20 @@ def test_valid_days():
for tz in ("America/New_York", "Europe/Berlin", None):
assert (valid.tz_localize(tz) == cal.valid_days(start, end, tz=tz)).all()

# test with dates with timezones attached
start = pd.Timestamp("2000-01-01", tz="America/New_York")
end = pd.Timestamp("2000-01-30", tz="America/New_York")
valid_w_tz = cal.valid_days(start, end, tz="UTC").tz_localize(None)
assert_index_equal(valid, valid_w_tz)


def test_valid_days_tz_aware():
calendar = NYSEExchangeCalendar()
data_date = dt.datetime.strptime("20250121", "%Y%m%d").astimezone(ZoneInfo("UTC"))
actual = calendar.valid_days(data_date, data_date + dt.timedelta(days=7), tz="UTC")
expected = pd.bdate_range("2025-01-21", periods=6, tz="UTC")
assert_index_equal(actual, expected)


def test_time_zone():
assert NYSEExchangeCalendar().tz == pytz.timezone("America/New_York")
Expand Down

0 comments on commit 47b3f1c

Please sign in to comment.