Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
staircase-dev committed Apr 25, 2023
2 parents a3e265f + a0cee55 commit 3b6565f
Show file tree
Hide file tree
Showing 17 changed files with 1,774 additions and 1,519 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
group: ${{ github.ref }}-pre-commit
cancel-in-progress: ${{github.event_name == 'pull_request'}}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/action@v2.0.0
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/action@v3.0.0
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
repos:
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]
name: isort
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 22.10.0
hooks:
- id: black
exclude: ^staircase/test_data*
- repo: https://gitlab.com/pycqa/flake8
rev: 4.0.1
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
- id: flake8
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020-2021 Riley Clement
Copyright (c) 2020-2023 Riley Clement

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion docs/getting_started/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ License

This project is licensed under the MIT License::

Copyright © 2020-2021 <Riley Clement>
Copyright © 2020-2023 <Riley Clement>

Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the “Software”), to deal in the Software
Expand Down
9 changes: 9 additions & 0 deletions docs/release_notes/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ Changelog
=========


**v2.5.1 2023-04-25**

- compatible with Pandas 2.0
- added type hints (#GH36)
- `mypy` added to development environment

Contributors: @PabloRuizCuevas


**v2.5.0 2022-10-19**

- dropped support for Python 3.6
Expand Down
3,016 changes: 1,591 additions & 1,425 deletions poetry.lock

Large diffs are not rendered by default.

45 changes: 34 additions & 11 deletions 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.5.0"
version = "2.5.1"
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 Expand Up @@ -34,21 +34,27 @@ classifiers=[
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Topic :: Scientific/Engineering',
]

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/staircase-dev/staircase/issues"


[tool.poetry.dependencies]
python = "^3.7"
matplotlib = ">=2"
pytz = "*"
typing-extensions = "^4.4.0"

[[tool.poetry.dependencies.pandas]]
python = ">=3.7,<3.10"
version = "^1"

[[tool.poetry.dependencies.pandas]]
python = "^3.10"
version = "^1.3.4"
version = ">=1.3.4,<3"

[[tool.poetry.dependencies.numpy]]
python = ">=3.7,<3.10"
Expand All @@ -59,8 +65,6 @@ python = "^3.10"
version = "^1.21.2"




[tool.poetry.dev-dependencies]
ipykernel = "^6"
pytest = "^6"
Expand All @@ -70,18 +74,37 @@ nbsphinx = ">=0.8.5"
sphinx-autobuild = "*"
seaborn = ">=0.8.0"
notebook = ">= 6.0"
isort = ">=5.8"
black = {version = "*", python = "^3.6.2"}
flake8 = ">=3.9"
pre-commit = {version = ">=2.13", python = "^3.6.1"}
isort = ">=5.8,<5.12"
black = ">=22.10"
flake8 = ">=5"
pre-commit = ">=2.20"
tox=">=3.15"

mypy = "^0.982"

[tool.poetry.extras]
codecov = ["codecov"]

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/staircase-dev/staircase/issues"
[tool.black]
line-length=88

[tool.mypy]
# disallow_untyped_defs='true'
# disallow_incomplete_defs='true'
# no_implicit_optional='true'
exclude = [
'^docs/.',
'^core/ops.',
'docstrings\\.pyi$',
'^tests/.',
'^staircase/plotting.',
]

[[tool.mypy.overrides]]
module=[
'matplotlib.*',
'pandas.*',
]
ignore_missing_imports='true'

[tool.isort]
# make it compatible with black
Expand Down
19 changes: 11 additions & 8 deletions staircase/constants.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
from __future__ import annotations


class NegInf:
def __init__(self):
pass

def __lt__(self, other):
def __lt__(self, other) -> bool:
assert not isinstance(other, NegInf)
return True

def __gt__(self, other):
def __gt__(self, other) -> bool:
assert not isinstance(other, (Inf, NegInf))
return False

def __neg__(self):
def __neg__(self) -> Inf:
return inf

def __str__(self):
def __str__(self) -> str:
return "-inf"


class Inf:
def __init__(self):
pass

def __gt__(self, other):
def __gt__(self, other) -> bool:
assert not isinstance(other, Inf)
return True

def __lt__(self, other):
def __lt__(self, other) -> bool:
assert not isinstance(other, (Inf, NegInf))
return False

def __neg__(self):
def __neg__(self) -> NegInf:
return neginf

def __str__(self):
def __str__(self) -> str:
return "inf"


Expand Down
4 changes: 2 additions & 2 deletions staircase/core/arrays/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ def __init__(self, pandas_obj):
self._obj = pandas_obj

@Appender(docstrings.make_docstring("accessor", "corr"), join="\n", indents=1)
def corr(self, where=(-inf, inf)):
def corr(self, where=(-inf, inf)) -> pd.DataFrame:
return pd.DataFrame(
self._obj.values.corr(where),
index=self._obj.index,
columns=self._obj.index,
)

@Appender(docstrings.make_docstring("accessor", "cov"), join="\n", indents=1)
def cov(self, where=(-inf, inf)):
def cov(self, where=(-inf, inf)) -> pd.DataFrame:
return pd.DataFrame(
self._obj.values.cov(where),
index=self._obj.index,
Expand Down
25 changes: 15 additions & 10 deletions staircase/core/arrays/extension.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import annotations

import numbers
from collections.abc import Iterable
from typing import Any, Callable, Type

import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -27,22 +30,22 @@ class StairsDtype(ExtensionDtype):
na_value = pd.NA

@classmethod
def construct_from_string(cls, string):
def construct_from_string(cls, string: str) -> StairsDtype:
if string == cls.name:
return cls()
else:
raise TypeError("Cannot construct a '{}' from '{}'".format(cls, string))

@classmethod
def construct_array_type(cls):
def construct_array_type(cls) -> Type[StairsArray]:
return StairsArray


def _isna(value):
def _isna(value: pd.Series) -> pd.Series:
return pd.isna(value)


def _make_logical(func):
def _make_logical(func: Callable) -> Callable:
def logical_func(x, axis=0):
return np.where(
np.logical_or.reduce(np.isnan(x), axis=axis),
Expand Down Expand Up @@ -75,13 +78,13 @@ def __init__(self, data):
raise TypeError("'data' should be array of Stairs objects.")

@property
def dtype(self):
def dtype(self) -> type:
return self._dtype

def __len__(self):
def __len__(self) -> int:
return len(self.data)

def __getitem__(self, idx):
def __getitem__(self, idx: int) -> Any:
if isinstance(idx, numbers.Integral):
return self.data[idx]
elif isinstance(idx, (Iterable, slice)):
Expand Down Expand Up @@ -185,7 +188,7 @@ def agg(self, func):
)._remove_redundant_step_points()

@Appender(docstrings.make_docstring("array", "sample"), join="\n", indents=1)
def sample(self, x):
def sample(self, x) -> pd.Series:
array = pd.Series(self.data)
return array.apply(Stairs.sample, x=x, include_index=True)

Expand Down Expand Up @@ -234,7 +237,7 @@ def negate(self):
__neg__ = negate


def _make_binary_func(func_str):
def _make_binary_func(func_str: str) -> Callable:

stairs_func = getattr(Stairs, func_str)
docstring = docstrings.make_binop_docstring(funcstr)
Expand Down Expand Up @@ -285,7 +288,9 @@ def func(self, other):
setattr(StairsArray, f"__{magic}__", func)


def _make_corr_cov_func(docstring, stairs_method, assume_ones_diagonal):
def _make_corr_cov_func(
docstring: str, stairs_method: Callable, assume_ones_diagonal: int
) -> Callable:
@Appender(docstring, join="\n", indents=1)
def func(self, where=(-inf, inf)):
size = len(self.data)
Expand Down
7 changes: 5 additions & 2 deletions staircase/core/layering.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import annotations

import datetime
import warnings
from typing import Any

import numpy as np
import pandas as pd
Expand All @@ -23,7 +26,7 @@ def _check_args_dtypes(*vectors):
is_numeric_dtype,
]

def _check_approved_dtype(vec):
def _check_approved_dtype(vec: pd.Series):
approved = any(map(lambda func: func(vec), approved_dtypes_checks))
if not approved:
warnings.warn(
Expand Down Expand Up @@ -59,7 +62,7 @@ def _check_approved_type(arg, approved_types):
_check_approved_type(end, tuple(base_approved_types + [NegInf]))


def _convert_to_series(vec):
def _convert_to_series(vec: Any) -> pd.Series:
if not isinstance(vec, pd.Series):
if vec is None or (isinstance(vec, (tuple, list)) and not len(vec)):
vec = pd.Series(vec, dtype="float64")
Expand Down
9 changes: 7 additions & 2 deletions staircase/core/sampling.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from __future__ import annotations

import numpy as np
import pandas as pd
from pandas.api.types import is_list_like

from staircase.core.stairs import Stairs
from staircase.docstrings import examples
from staircase.util import _is_datetime_like
from staircase.util._decorators import Appender


# capable of single or vector
@Appender(examples.sample_example, join="\n", indents=1)
def sample(self, x, include_index=False):
def sample(
self: Stairs, x: int | float | np.array | pd.Series, include_index=False
) -> pd.Series:
"""
Evaluates the value of the step function at one, or more, points.
Expand Down Expand Up @@ -42,7 +47,7 @@ def sample(self, x, include_index=False):


@Appender(examples.limit_example, join="\n", indents=1)
def limit(self, x, side, include_index=False):
def limit(self: Stairs, x, side, include_index=False) -> pd.Series:
"""
Evaluates the limit of the step function as it approaches one, or more, points.
Expand Down
Loading

0 comments on commit 3b6565f

Please sign in to comment.