Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
venaturum committed May 13, 2022
2 parents 333f425 + 9524ac7 commit e47423f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
5 changes: 5 additions & 0 deletions docs/release_notes/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Changelog
=========


**v2.4.2 2022-05-13**

- bugfix for using :meth:`staircase.Stairs.from_values` with timezone aware DatetimeIndex on `values` argument (#GH145)


**v2.4.1 2022-05-09**

- bugfix for empty Series warning generated by pandas when `start` or `end` arguments for :meth:`staircase.Stairs.layer` are `None` or empty list (#GH143)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "poetry.masonry.api"

[tool.poetry]
name = "staircase"
version = "2.4.1"
version = "2.4.2"
description = "A data analysis package based on modelling and manipulation of mathematical step functions. Strongly aligned with pandas."
readme = "README.md"
authors = ["Riley Clement <venaturum@gmail.com>"]
Expand Down
8 changes: 4 additions & 4 deletions staircase/core/layering.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from staircase.util._decorators import Appender


def _check_args_dtypes(start, end):
def _check_args_dtypes(*vectors):
approved_dtypes_checks = [
is_datetime64_any_dtype,
is_timedelta64_dtype,
Expand All @@ -27,11 +27,11 @@ def _check_approved_dtype(vec):
approved = any(map(lambda func: func(vec), approved_dtypes_checks))
if not approved:
warnings.warn(
f"An argument supplied for 'start' or 'end' has dtype {vec.dtype}. Only numerical, datetime-like, or timedelta dtypes have been tested. Using other dtypes is considered experimental."
f"An argument supplied has dtype {vec.dtype}. Only numerical, datetime-like, or timedelta dtypes have been tested. Using other dtypes is considered experimental."
)

_check_approved_dtype(start)
_check_approved_dtype(end)
for vec in vectors:
_check_approved_dtype(vec)


def _check_args_types(start, end):
Expand Down
10 changes: 3 additions & 7 deletions staircase/core/stairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from staircase.constants import inf
from staircase.core import stats
from staircase.core.accessor import CachedAccessor
from staircase.core.layering import _check_args_dtypes
from staircase.plotting.accessor import PlotAccessor
from staircase.util import _replace_none_with_infs
from staircase.util._decorators import Appender
Expand Down Expand Up @@ -108,14 +109,9 @@ def from_values(cls, initial_value, values=None, closed="left"):
if not isinstance(values, pd.Series) or values.empty:
raise ValueError("values must be a not empty Series")

if not (
is_numeric_dtype(values.index)
or is_datetime64_dtype(values.index)
or is_timedelta64_dtype(values.index)
):
warnings.warn("The index of data is not numeric, or time based")
_check_args_dtypes(values.index)

if np.isinf(values.index).any():
if is_numeric_dtype(values.index) and np.isinf(values.index).any():
raise ValueError("Invalid value for Series index")

if not is_numeric_dtype(values) or not is_number(initial_value):
Expand Down
23 changes: 23 additions & 0 deletions tests/test_dates/test_dates_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,26 @@ def test_clip_expected_type(date_func, kwargs):
kwargs = {key: timestamp(*val, date_func=date_func) for key, val in kwargs.items()}
result = s1(date_func).clip(**kwargs)
assert_expected_type(result, date_func)


def test_from_values(date_func):
# this corresponds to the step function produced by S1 method
values = pd.Series(
[2, 4.5, 2, -0.5, 0],
index=[
timestamp(2020, 1, 1, date_func=date_func),
timestamp(2020, 1, 3, date_func=date_func),
timestamp(2020, 1, 5, date_func=date_func),
timestamp(2020, 1, 6, date_func=date_func),
timestamp(2020, 1, 10, date_func=date_func),
],
)

sf = Stairs.from_values(
initial_value=0,
values=values,
)

print(sf._data)
print(s1(date_func)._data)
assert sf.identical(s1(date_func))

0 comments on commit e47423f

Please sign in to comment.