Skip to content
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
23 changes: 23 additions & 0 deletions arch/tests/utility/test_array.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from abc import abstractmethod
import datetime as dt
import re

import numpy as np
from numpy.random import RandomState
Expand Down Expand Up @@ -445,6 +446,28 @@ def test_date_to_index_tz_aware_not_monotonic():
date_to_index("2021-03-14", date_index)


@pytest.mark.filterwarnings(*NO_DEPRECATIONS)
@pytest.mark.parametrize("tz", [None, "Asia/Kolkata"])
@pytest.mark.parametrize("box", [Series, DatetimeIndex])
@pytest.mark.parametrize(
("positions", "rule"),
[
([1, 0, 2], "increasing and unique"),
([0, 1, 1], "increasing and unique"),
([], "a non-empty array of dates"),
],
)
def test_date_to_index_error_describes_input(tz, box, positions, rule):
# The error describes date_index as it was passed, not as it was converted
dates = date_range("2021-03-13", periods=3, tz=tz)[positions]
date_index = box(dates)
message = (
f"date_index must be {rule}; got shape ({len(positions)},) ({box.__name__})"
)
with pytest.raises(ValueError, match=re.escape(message)):
date_to_index("2021-03-14", date_index)


def test_date_to_index_timestamp():
dr = date_range("20000101", periods=3000, freq="W")
y = Series(np.arange(3000.0), index=dr)
Expand Down
19 changes: 11 additions & 8 deletions arch/utility/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ def date_to_index(
----------
date : str, datetime, datetime64 or Timestamp
Date to use when returning the index.
date_index : DatetimeIndex or ndarray
date_index : DatetimeIndex, Series or ndarray
Index data containing datetime64 values.

Returns
Expand Down Expand Up @@ -804,16 +804,19 @@ def date_to_index(
"a datetime64 array",
_describe(date_index),
)
if isinstance(date_index, Series):
date_index = DatetimeIndex(date_index)
if isinstance(date_index, DatetimeIndex):
if date_index.tzinfo is not None:
# The errors describe date_index as it was passed, so the converted dates are kept
# separately
dates = date_index
if isinstance(dates, Series):
dates = DatetimeIndex(dates)
if isinstance(dates, DatetimeIndex):
if dates.tzinfo is not None:
# The same UTC values without a time zone that .values returned. Using
# .values is deprecated for time zone aware indices.
date_index = date_index.tz_convert("GMT").tz_localize(None)
values = date_index.to_numpy()
dates = dates.tz_convert("GMT").tz_localize(None)
values = dates.to_numpy()
else:
values = np.asarray(date_index)
values = np.asarray(dates)
if values.shape[0] == 0:
_fail(
ValueError,
Expand Down
3 changes: 3 additions & 0 deletions doc/source/changes/9.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,9 @@ Bug fixes
- The output of :class:`~arch.utility.testing.WaldTestStatistic` shows the name of the
test once, as its first line. Since 4.8.0 the name was also printed between the null
and the alternative hypotheses. Contributed by sohailshk (:issue:`1014`).
- ``date_to_index`` in ``arch.utility.array`` accepts a ``Series`` of time zone aware
dates, as it accepts a time zone aware ``DatetimeIndex``, where it raised a
``TypeError``. Contributed by jackiectl2 (:issue:`1016`).
- Fixed ``SkewStudent.ppf`` for probabilities close to 1, which lost precision and
returned ``inf`` for some probabilities below 1. For example, with :math:`\eta=8` and
:math:`\lambda=0.9` the quantile of the largest float below 1 was ``inf`` and is
Expand Down
Loading