Skip to content
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

Update dependencies and changes for pandas 2.0 #299

Merged
merged 2 commits into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions etc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
#
# This file is autogenerated by pip-compile with python 3.8
# To update, run:
# This file is autogenerated by pip-compile with Python 3.8
# by the following command:
#
# pip-compile --output-file=etc/requirements.txt pyproject.toml
#
korean-lunar-calendar==0.3.1
# via exchange-calendars (pyproject.toml)
numpy==1.24.1
numpy==1.24.2
# via
# exchange-calendars (pyproject.toml)
# pandas
pandas==1.5.2
pandas==2.0.0
# via exchange-calendars (pyproject.toml)
pyluach==2.0.2
pyluach==2.2.0
# via exchange-calendars (pyproject.toml)
python-dateutil==2.8.2
# via
# exchange-calendars (pyproject.toml)
# pandas
pytz==2022.7
pytz==2023.3
# via
# exchange-calendars (pyproject.toml)
# pandas
six==1.16.0
# via python-dateutil
toolz==0.12.0
# via exchange-calendars (pyproject.toml)
tzdata==2023.3
# via pandas
37 changes: 19 additions & 18 deletions etc/requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#
# This file is autogenerated by pip-compile with python 3.8
# To update, run:
# This file is autogenerated by pip-compile with Python 3.8
# by the following command:
#
# pip-compile --extra=dev --output-file=etc/requirements_dev.txt pyproject.toml
#
attrs==22.2.0
# via
# hypothesis
# pytest
build==0.9.0
build==0.10.0
# via pip-tools
click==8.1.3
# via pip-tools
Expand All @@ -17,35 +17,33 @@ colorama==0.4.6
# build
# click
# pytest
exceptiongroup==1.1.0
exceptiongroup==1.1.1
# via
# hypothesis
# pytest
execnet==1.9.0
# via pytest-xdist
flake8==6.0.0
# via exchange-calendars (pyproject.toml)
hypothesis==6.61.0
hypothesis==6.71.0
# via exchange-calendars (pyproject.toml)
iniconfig==1.1.1
iniconfig==2.0.0
# via pytest
korean-lunar-calendar==0.3.1
# via exchange-calendars (pyproject.toml)
mccabe==0.7.0
# via flake8
numpy==1.24.1
numpy==1.24.2
# via
# exchange-calendars (pyproject.toml)
# pandas
packaging==22.0
packaging==23.0
# via
# build
# pytest
pandas==1.5.2
pandas==2.0.0
# via exchange-calendars (pyproject.toml)
pep517==0.13.0
# via build
pip-tools==6.12.1
pip-tools==6.13.0
# via exchange-calendars (pyproject.toml)
pluggy==1.0.0
# via pytest
Expand All @@ -55,22 +53,24 @@ pycodestyle==2.10.0
# via flake8
pyflakes==3.0.1
# via flake8
pyluach==2.0.2
pyluach==2.2.0
# via exchange-calendars (pyproject.toml)
pytest==7.2.0
pyproject-hooks==1.0.0
# via build
pytest==7.2.2
# via
# exchange-calendars (pyproject.toml)
# pytest-benchmark
# pytest-xdist
pytest-benchmark==4.0.0
# via exchange-calendars (pyproject.toml)
pytest-xdist==3.1.0
pytest-xdist==3.2.1
# via exchange-calendars (pyproject.toml)
python-dateutil==2.8.2
# via
# exchange-calendars (pyproject.toml)
# pandas
pytz==2022.7
pytz==2023.3
# via
# exchange-calendars (pyproject.toml)
# pandas
Expand All @@ -81,11 +81,12 @@ sortedcontainers==2.4.0
tomli==2.0.1
# via
# build
# pep517
# pytest
toolz==0.12.0
# via exchange-calendars (pyproject.toml)
wheel==0.38.4
tzdata==2023.3
# via pandas
wheel==0.40.0
# via pip-tools

# The following packages are considered to be unsafe in a requirements file:
Expand Down
33 changes: 16 additions & 17 deletions etc/requirements_minpandas.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This file is autogenerated by pip-compile with python 3.8
# To update, run:
# This file is autogenerated by pip-compile with Python 3.8
# by the following command:
#
# pip-compile --extra=dev --output-file=etc/requirements_minpandas.txt pyproject.toml
#
Expand All @@ -12,7 +12,7 @@ attrs==22.2.0
# via
# hypothesis
# pytest
build==0.9.0
build==0.10.0
# via pip-tools
click==8.1.3
# via pip-tools
Expand All @@ -21,35 +21,33 @@ colorama==0.4.6
# build
# click
# pytest
exceptiongroup==1.1.0
exceptiongroup==1.1.1
# via
# hypothesis
# pytest
execnet==1.9.0
# via pytest-xdist
flake8==6.0.0
# via exchange-calendars (pyproject.toml)
hypothesis==6.61.0
hypothesis==6.71.0
# via exchange-calendars (pyproject.toml)
iniconfig==1.1.1
iniconfig==2.0.0
# via pytest
korean-lunar-calendar==0.3.1
# via exchange-calendars (pyproject.toml)
mccabe==0.7.0
# via flake8
numpy==1.24.1
numpy==1.24.2
# via
# exchange-calendars (pyproject.toml)
# pandas
packaging==22.0
packaging==23.0
# via
# build
# pytest
pandas==1.1.0
# via exchange-calendars (pyproject.toml)
pep517==0.13.0
# via build
pip-tools==6.12.1
pip-tools==6.13.0
# via exchange-calendars (pyproject.toml)
pluggy==1.0.0
# via pytest
Expand All @@ -59,22 +57,24 @@ pycodestyle==2.10.0
# via flake8
pyflakes==3.0.1
# via flake8
pyluach==2.0.2
pyluach==2.2.0
# via exchange-calendars (pyproject.toml)
pytest==7.2.0
pyproject-hooks==1.0.0
# via build
pytest==7.2.2
# via
# exchange-calendars (pyproject.toml)
# pytest-benchmark
# pytest-xdist
pytest-benchmark==4.0.0
# via exchange-calendars (pyproject.toml)
pytest-xdist==3.1.0
pytest-xdist==3.2.1
# via exchange-calendars (pyproject.toml)
python-dateutil==2.8.2
# via
# exchange-calendars (pyproject.toml)
# pandas
pytz==2022.7
pytz==2023.3
# via
# exchange-calendars (pyproject.toml)
# pandas
Expand All @@ -85,11 +85,10 @@ sortedcontainers==2.4.0
tomli==2.0.1
# via
# build
# pep517
# pytest
toolz==0.12.0
# via exchange-calendars (pyproject.toml)
wheel==0.38.4
wheel==0.40.0
# via pip-tools

# The following packages are considered to be unsafe in a requirements file:
Expand Down
6 changes: 3 additions & 3 deletions exchange_calendars/calendar_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def trading_index(self) -> pd.DatetimeIndex:
index = self._trading_index()
if self.has_break:
index.sort()
index = pd.DatetimeIndex(index, tz="UTC")
index = pd.DatetimeIndex(index, tz=pytz.UTC)
return self.curtail_for_times(index)

@contextlib.contextmanager
Expand Down Expand Up @@ -718,7 +718,7 @@ def trading_index_intervals(self) -> pd.IntervalIndex:
else:
raise errors.IntervalsOverlapError()

left = pd.DatetimeIndex(left, tz="UTC")
right = pd.DatetimeIndex(right, tz="UTC")
left = pd.DatetimeIndex(left, tz=pytz.UTC)
right = pd.DatetimeIndex(right, tz=pytz.UTC)
index = pd.IntervalIndex.from_arrays(left, right, self.closed)
return self.curtail_for_times(index)
2 changes: 1 addition & 1 deletion exchange_calendars/pandas_extensions/offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _apply(self, other):
bday, interval = self._custom_business_day_for(
other, remaining, with_interval=True
)
result = bday.apply(other)
result = bday + other
while not interval.left <= result <= interval.right:
previous_other = other
if result < interval.left:
Expand Down
2 changes: 1 addition & 1 deletion exchange_calendars/utils/pandas_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def longest_run(ser: pd.Series) -> pd.Index:
... | ((ser >= 55) & (ser < 61))
... )
>>> longest_run(bv)
Int64Index([30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40], dtype='int64')
Index([30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40], dtype='int32')
>>> pd.testing.assert_index_equal(longest_run(bv), ser.index[30:41])
"""
# group Trues by only adding to sum when value False.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_calendar_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def bounds(start: pd.Series, end: pd.Series, force: bool, align: pd.Timedelta):

if curtail and not (force_close and force_break_close):
indices = lower_bounds.argsort()
lower_bounds.sort_values(inplace=True)
lower_bounds = lower_bounds.sort_values()
upper_bounds = upper_bounds[indices]
curtail_mask = upper_bounds > lower_bounds.shift(-1)
if curtail_mask.any():
Expand Down
16 changes: 11 additions & 5 deletions tests/test_exchange_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# limitations under the License.
from __future__ import annotations

import datetime
import functools
import itertools
import pathlib
Expand Down Expand Up @@ -181,7 +182,6 @@ def get_csv(name: str) -> pd.DataFrame:
path,
index_col=0,
parse_dates=[0, 1, 2, 3, 4],
infer_datetime_format=True,
)
# Necessary for csv saved prior to v4.0
if df.index.tz is not None:
Expand All @@ -190,6 +190,8 @@ def get_csv(name: str) -> pd.DataFrame:
for col in df:
if df[col].dt.tz is None:
df[col] = df[col].dt.tz_localize(UTC)
elif df[col].dt.tz is datetime.timezone.utc:
df[col] = df[col].dt.tz_convert(UTC)
return df


Expand Down Expand Up @@ -2146,7 +2148,7 @@ def late_opens(
date_to = pd.Timestamp.max
dtis: list[pd.DatetimeIndex] = []
# For each period over which a distinct open time prevails...
for date_from, time_ in s.iteritems():
for date_from, time_ in s.items():
opens = ans.opens[date_from:date_to]
sessions = opens.index
td = pd.Timedelta(hours=time_.hour, minutes=time_.minute)
Expand Down Expand Up @@ -2186,7 +2188,7 @@ def early_closes(

date_to = pd.Timestamp.max
dtis: list[pd.DatetimeIndex] = []
for date_from, time_ in s.iteritems():
for date_from, time_ in s.items():
closes = ans.closes[date_from:date_to] # index to tz-naive
sessions = closes.index
td = pd.Timedelta(hours=time_.hour, minutes=time_.minute)
Expand Down Expand Up @@ -3837,14 +3839,18 @@ def unite(dtis: list[pd.DatetimeIndex]) -> pd.DatetimeIndex:
else:
ends = ans.closes
# index for a 'left' calendar, add end so evaluated as if 'both'
index = index.append(pd.DatetimeIndex([ends[session]]))
index = index.append(
pd.DatetimeIndex([ends[session]], tz=pytz.UTC)
)

index = index[::mins] # only want every period
if not index[-1] == ends[session]:
# if period doesn't coincide with end, add right side of
# last interval which lies beyond end.
last_indice = index[-1] + period
index = index.append(pd.DatetimeIndex([last_indice]))
index = index.append(
pd.DatetimeIndex([last_indice], tz=pytz.UTC)
)
dtis.append(index)

both_index = unite(dtis)
Expand Down