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 fix pandas 2.2 deprecation warnings #358

Merged
merged 2 commits into from
Jan 31, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: |
pytest etc/bench.py --benchmark-json output.json
- name: Download previous benchmark data
uses: actions/cache@v3.3.3
uses: actions/cache@v4.0.0
with:
path: ./cache
key: ${{ runner.os }}-benchmark
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Timestamp('2022-01-03 00:00:00', freq='C')
Timestamp('2022-01-10 00:00:00', freq='C')

>>> xhkg.trading_index(
... "2021-12-30", "2021-12-31", period="90T", force=True
... "2021-12-30", "2021-12-31", period="90min", force=True
... )
IntervalIndex([[2021-12-30 01:30:00, 2021-12-30 03:00:00), [2021-12-30 03:00:00, 2021-12-30 04:00:00), [2021-12-30 05:00:00, 2021-12-30 06:30:00), [2021-12-30 06:30:00, 2021-12-30 08:00:00), [2021-12-31 01:30:00, 2021-12-31 03:00:00), [2021-12-31 03:00:00, 2021-12-31 04:00:00)], dtype='interval[datetime64[ns, UTC], left]')
```
Expand Down
17 changes: 6 additions & 11 deletions etc/ecal
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/usr/bin/env python
from __future__ import print_function

import io
import sys

import pandas as pd


months = [
"January",
"February",
Expand All @@ -25,24 +29,15 @@ def error(msg):


def _render_month(calendar, year, month, print_year):
import pandas as pd

if sys.version_info[0] == 2:
import StringIO

out = StringIO.StringIO()
else:
import io

out = io.StringIO()
out = io.StringIO()

start = "{year}-{month}".format(year=year, month=month)
if month == 12:
end = "{year}-{month}".format(year=year + 1, month=1)
else:
end = "{year}-{month}".format(year=year, month=month + 1)

days = pd.date_range(start, end, closed="left", tz='utc')
days = pd.date_range(start, end, tz="utc")

title = months[month - 1]
if print_year:
Expand Down
12 changes: 5 additions & 7 deletions etc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@
#
korean-lunar-calendar==0.3.1
# via exchange_calendars (pyproject.toml)
numpy==1.26.2
numpy==1.26.3
# via
# exchange_calendars (pyproject.toml)
# pandas
pandas==2.1.4
pandas==2.2.0
# via exchange_calendars (pyproject.toml)
pyluach==2.2.0
# via exchange_calendars (pyproject.toml)
python-dateutil==2.8.2
# via
# exchange_calendars (pyproject.toml)
# pandas
pytz==2023.3.post1
# via pandas
pytz==2023.4
# via pandas
six==1.16.0
# via python-dateutil
toolz==0.12.0
toolz==0.12.1
# via exchange_calendars (pyproject.toml)
tzdata==2023.4
# via
Expand Down
22 changes: 10 additions & 12 deletions etc/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ exceptiongroup==1.2.0
# pytest
execnet==2.0.2
# via pytest-xdist
flake8==6.1.0
flake8==7.0.0
# via exchange_calendars (pyproject.toml)
hypothesis==6.92.2
hypothesis==6.97.3
# via exchange_calendars (pyproject.toml)
importlib-metadata==7.0.1
# via build
Expand All @@ -33,31 +33,31 @@ korean-lunar-calendar==0.3.1
# via exchange_calendars (pyproject.toml)
mccabe==0.7.0
# via flake8
numpy==1.26.2
numpy==1.26.3
# via
# exchange_calendars (pyproject.toml)
# pandas
packaging==23.2
# via
# build
# pytest
pandas==2.1.4
pandas==2.2.0
# via exchange_calendars (pyproject.toml)
pip-tools==7.3.0
# via exchange_calendars (pyproject.toml)
pluggy==1.3.0
pluggy==1.4.0
# via pytest
py-cpuinfo==9.0.0
# via pytest-benchmark
pycodestyle==2.11.1
# via flake8
pyflakes==3.1.0
pyflakes==3.2.0
# via flake8
pyluach==2.2.0
# via exchange_calendars (pyproject.toml)
pyproject-hooks==1.0.0
# via build
pytest==7.4.4
pytest==8.0.0
# via
# exchange_calendars (pyproject.toml)
# pytest-benchmark
Expand All @@ -67,10 +67,8 @@ pytest-benchmark==4.0.0
pytest-xdist==3.5.0
# via exchange_calendars (pyproject.toml)
python-dateutil==2.8.2
# via
# exchange_calendars (pyproject.toml)
# pandas
pytz==2023.3.post1
# via pandas
pytz==2023.4
# via pandas
six==1.16.0
# via python-dateutil
Expand All @@ -82,7 +80,7 @@ tomli==2.0.1
# pip-tools
# pyproject-hooks
# pytest
toolz==0.12.0
toolz==0.12.1
# via exchange_calendars (pyproject.toml)
tzdata==2023.4
# via
Expand Down
21 changes: 10 additions & 11 deletions etc/requirements_minpandas.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# To upgrade with pandas==1.5 fixed run:
#
# pip-compile --upgrade --upgrade-package pandas==1.5 --extra=dev --output-file=etc/requirements_minpandas.txt pyproject.toml

#
attrs==23.2.0
# via hypothesis
Expand All @@ -25,9 +26,9 @@ exceptiongroup==1.2.0
# pytest
execnet==2.0.2
# via pytest-xdist
flake8==6.1.0
flake8==7.0.0
# via exchange_calendars (pyproject.toml)
hypothesis==6.92.2
hypothesis==6.97.3
# via exchange_calendars (pyproject.toml)
importlib-metadata==7.0.1
# via build
Expand All @@ -37,7 +38,7 @@ korean-lunar-calendar==0.3.1
# via exchange_calendars (pyproject.toml)
mccabe==0.7.0
# via flake8
numpy==1.26.2
numpy==1.26.3
# via
# exchange_calendars (pyproject.toml)
# pandas
Expand All @@ -49,19 +50,19 @@ pandas==1.5.0
# via exchange_calendars (pyproject.toml)
pip-tools==7.3.0
# via exchange_calendars (pyproject.toml)
pluggy==1.3.0
pluggy==1.4.0
# via pytest
py-cpuinfo==9.0.0
# via pytest-benchmark
pycodestyle==2.11.1
# via flake8
pyflakes==3.1.0
pyflakes==3.2.0
# via flake8
pyluach==2.2.0
# via exchange_calendars (pyproject.toml)
pyproject-hooks==1.0.0
# via build
pytest==7.4.4
pytest==8.0.0
# via
# exchange_calendars (pyproject.toml)
# pytest-benchmark
Expand All @@ -71,10 +72,8 @@ pytest-benchmark==4.0.0
pytest-xdist==3.5.0
# via exchange_calendars (pyproject.toml)
python-dateutil==2.8.2
# via
# exchange_calendars (pyproject.toml)
# pandas
pytz==2023.3.post1
# via pandas
pytz==2023.4
# via pandas
six==1.16.0
# via python-dateutil
Expand All @@ -86,7 +85,7 @@ tomli==2.0.1
# pip-tools
# pyproject-hooks
# pytest
toolz==0.12.0
toolz==0.12.1
# via exchange_calendars (pyproject.toml)
tzdata==2023.4
# via exchange_calendars (pyproject.toml)
Expand Down
8 changes: 4 additions & 4 deletions exchange_calendars/calendar_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ def parse_timestamp(
)
side = side if side is not None else calendar.side
if side == "left":
ts = ts.floor("T")
ts = ts.floor("min")
elif side == "right":
ts = ts.ceil("T")
ts = ts.ceil("min")
else:
raise ValueError(
"`timestamp` cannot have a non-zero second (or more accurate)"
Expand Down Expand Up @@ -493,7 +493,7 @@ def align_opens(opens: pd.Series, align: pd.Timedelta) -> np.ndarray:
opens = opens.dt.ceil(align)
return opens.values.astype(np.int64)

if align != pd.Timedelta(1, "T"):
if align != pd.Timedelta(1, "min"):
self.opens = align_opens(calendar.opens[slce], align)
else:
self.opens = calendar.opens_nanos[slce]
Expand All @@ -503,7 +503,7 @@ def align_opens(opens: pd.Series, align: pd.Timedelta) -> np.ndarray:
else:
self.break_starts = calendar.break_starts_nanos[slce]

if align_pm != pd.Timedelta(1, "T"):
if align_pm != pd.Timedelta(1, "min"):
self.break_ends = align_opens(calendar.break_ends[slce], align_pm)
else:
self.break_ends = calendar.break_ends_nanos[slce]
Expand Down
18 changes: 9 additions & 9 deletions exchange_calendars/exchange_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2344,7 +2344,7 @@ def trading_index(
force: bool | None = None,
curtail_overlaps: bool = False,
ignore_breaks: bool = False,
align: pd.Timedelta | str = pd.Timedelta(1, "T"),
align: pd.Timedelta | str = pd.Timedelta(1, "min"),
align_pm: pd.Timedelta | bool = True,
parse: bool = True,
) -> pd.DatetimeIndex | pd.IntervalIndex:
Expand Down Expand Up @@ -2538,7 +2538,7 @@ def trading_index(
component then can pass `parse` as False to save around
500µs on the execution.

align : default: pd.Timedelta(1, "T")
align : default: pd.Timedelta(1, "min")
Anchor the first indice of each session such that it aligns
with the nearest occurrence of a specific fraction of an hour.

Expand All @@ -2547,14 +2547,14 @@ def trading_index(
forwards, -ve values to shift indices backwards.

Valid values are (or equivalent):
"2T", "3T", "4T", "5T", "6T", "10T", "12T", "15T", "20T",
"30T", "-2T", "-4T", "-5T", "-6T", "-10T", "-12T", "-15T",
"-20T", "-30T"
"2min", "3min", "4min", "5min", "6min", "10min", "12min", "15min", "20min",
"30min", "-2min", "-4min", "-5min", "-6min", "-10min", "-12min", "-15min",
"-20min", "-30min"

For example, if `intervals` is True and `period` is '5T' then
the first interval of a session with open time as 07:59 would
be:
07:59 - 08:04 if `align` is pd.Timedelta(1, "T") (default)
07:59 - 08:04 if `align` is pd.Timedelta(1, "min") (default)
08:00 - 08:05 if `align` is '5T'
07:55 - 08:00 if `align` is '-5T'

Expand Down Expand Up @@ -2662,13 +2662,13 @@ def get_align(name: Literal["align", "align_pm"], value: Any) -> pd.Timedelta:
)
raise ValueError(msg) from None

ONE_HOUR = pd.Timedelta("1H")
ONE_HOUR = pd.Timedelta("1h")
if value > ONE_HOUR or value < -ONE_HOUR or not value or (ONE_HOUR % value):
raise ValueError(
f"`{name}` must be factor of 1H although received '{value}'."
)

if value % pd.Timedelta(1, "T"):
if value % pd.Timedelta(1, "min"):
raise ValueError(
f"`{name}` cannot include a fraction of a minute although received"
f" '{value}'."
Expand All @@ -2678,7 +2678,7 @@ def get_align(name: Literal["align", "align_pm"], value: Any) -> pd.Timedelta:
align = get_align("align", align)

if align_pm is False:
align_pm = pd.Timedelta(1, "T")
align_pm = pd.Timedelta(1, "min")
else:
align_pm = align if align_pm is True else get_align("align_pm", align_pm)

Expand Down
4 changes: 2 additions & 2 deletions exchange_calendars/utils/pandas_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ def indexes_union(indexes: list[pd.Index]) -> pd.Index:

Examples
--------
>>> index1 = pd.date_range('2021-05-01 12:20', periods=2, freq='1H')
>>> index2 = pd.date_range('2021-05-02 17:10', periods=2, freq='22T')
>>> index1 = pd.date_range('2021-05-01 12:20', periods=2, freq='1h')
>>> index2 = pd.date_range('2021-05-02 17:10', periods=2, freq='22min')
>>> index3 = pd.date_range('2021-05-03', periods=2, freq='1D')
>>> indexes_union([index1, index2, index3])
DatetimeIndex(['2021-05-01 12:20:00', '2021-05-01 13:20:00',
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"numpy",
"numpy<2",
"pandas>=1.5",
"pyluach",
"python-dateutil",
"toolz",
"tzdata",
"korean_lunar_calendar",
Expand Down
Loading
Loading