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

Fix tests, README links #72

Merged
merged 14 commits into from
Sep 1, 2023
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,15 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: "pip" # Caching pip dependencies.
- name: Install dependencies
if: matrix.python-version != '3.7'
run: |
pip install --upgrade pip
pip install .[dev]
- name: Install dependencies (python 3.7, use legacy resolver)
if: matrix.python-version == '3.7'
run: |
pip install --upgrade pip
pip install .[dev] --use-deprecated=legacy-resolver
- name: Test with pytest (xdist)
if: matrix.os != 'ubuntu-latest'
run: pytest -vvvx -n auto -m "not slow and not extra and not skipci" --durations=50 --cov
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/test_full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: "pip" # Caching pip dependencies.
- name: Install dependencies
if: matrix.python-version != '3.7'
run: |
pip install --upgrade pip
pip install .[dev]
- name: Install dependencies (python 3.7, use legacy resolver)
if: matrix.python-version == '3.7'
run: |
pip install --upgrade pip
pip install .[dev] --use-deprecated=legacy-resolver
- name: Test with pytest (xdist)
if: matrix.os != 'ubuntu-latest'
run: pytest -vvvx -n auto -m "not skipci" --durations=50 --cov
Expand Down
20 changes: 8 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exclude: '^docs/conf.py'
# exclude: '^docs/conf.py' # If need global exclude.

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -22,6 +22,7 @@ repos:
exclude: 'docs/user_guide' # Auto-generated, leave as is.
- id: pretty-format-json
args: ['--autofix', '--indent=4', '--no-sort-keys']
exclude: '.*.ipynb' # ipynb may get treated as JSON, don't want that.
- id: requirements-txt-fixer
exclude: docs/requirements.txt
- id: mixed-line-ending
Expand All @@ -33,39 +34,34 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.7.0
hooks:
- id: black-jupyter
language_version: python3
args: [
"--force-exclude=docs/conf.py"
]

# If like to embrace black styles even in the docs:
- repo: https://github.com/asottile/blacken-docs
rev: v1.12.1
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies: [black]
exclude: 'docs/user_guide' # Auto-generated, leave as is.

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8
## You can add flake8 plugins via `additional_dependencies`:
# additional_dependencies: [flake8-bugbear]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.1.1
rev: v1.5.1
hooks:
- id: mypy
files: "^src/"
args: [--config-file=mypy.ini]
additional_dependencies: [pydantic]
additional_dependencies: [pydantic<2]

- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
rev: 1.7.5
hooks:
- id: bandit
args: ["-c", "pyproject.toml", "-q"]
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-->

<!-- exclude_docs -->
[![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/user_guide/tutorial04_prediction.ipynb)
[![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/usage/tutorial04_prediction.ipynb)
[![Documentation Status](https://readthedocs.org/projects/temporai/badge/?version=latest)](https://temporai.readthedocs.io/en/latest/?badge=latest)

[![Python 3.7+](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/downloads/release/python-370/)
Expand Down Expand Up @@ -423,15 +423,15 @@ Prediction where targets are temporal (time series).
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/data/tutorial04_data_splitting.ipynb) - [Data Splitting](./tutorials/data/tutorial04_data_splitting.ipynb)

### User Guide
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/user_guide/tutorial01_plugins.ipynb) - [Plugins](./tutorials/user_guide/tutorial01_plugins.ipynb)
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/user_guide/tutorial02_imputation.ipynb) - [Imputation](./tutorials/user_guide/tutorial02_imputation.ipynb)
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/user_guide/tutorial03_scaling.ipynb) - [Scaling](./tutorials/user_guide/tutorial03_scaling.ipynb)
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/user_guide/tutorial04_prediction.ipynb) - [Prediction](./tutorials/user_guide/tutorial04_prediction.ipynb)
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/user_guide/tutorial05_time_to_event.ipynb) - [Time-to-event Analysis](./tutorials/user_guide/tutorial05_time_to_event.ipynb)
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/user_guide/tutorial06_treatments.ipynb) - [Treatment Effects](./tutorials/user_guide/tutorial06_treatments.ipynb)
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/user_guide/tutorial07_pipeline.ipynb) - [Pipeline](./tutorials/user_guide/tutorial07_pipeline.ipynb)
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/user_guide/tutorial08_benchmarks.ipynb) - [Benchmarks](./tutorials/user_guide/tutorial08_benchmarks.ipynb)
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/user_guide/tutorial09_automl.ipynb) - [AutoML](./tutorials/user_guide/tutorial09_automl.ipynb)
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/usage/tutorial01_plugins.ipynb) - [Plugins](./tutorials/usage/tutorial01_plugins.ipynb)
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/usage/tutorial02_imputation.ipynb) - [Imputation](./tutorials/usage/tutorial02_imputation.ipynb)
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/usage/tutorial03_scaling.ipynb) - [Scaling](./tutorials/usage/tutorial03_scaling.ipynb)
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/usage/tutorial04_prediction.ipynb) - [Prediction](./tutorials/usage/tutorial04_prediction.ipynb)
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/usage/tutorial05_time_to_event.ipynb) - [Time-to-event Analysis](./tutorials/usage/tutorial05_time_to_event.ipynb)
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/usage/tutorial06_treatments.ipynb) - [Treatment Effects](./tutorials/usage/tutorial06_treatments.ipynb)
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/usage/tutorial07_pipeline.ipynb) - [Pipeline](./tutorials/usage/tutorial07_pipeline.ipynb)
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/usage/tutorial08_benchmarks.ipynb) - [Benchmarks](./tutorials/usage/tutorial08_benchmarks.ipynb)
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/usage/tutorial09_automl.ipynb) - [AutoML](./tutorials/usage/tutorial09_automl.ipynb)

### Extending TemporAI
- [![Test In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vanderschaarlab/temporai/blob/main/tutorials/extending/tutorial01_custom_plugin.ipynb) - [Writing a Custom Plugin](./tutorials/extending/tutorial01_custom_plugin.ipynb)
Expand Down
8 changes: 8 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ filterwarnings =
ignore:.*rsyncdir.*:DeprecationWarning
# Jupyter platformdirs-related warning, ignore:
ignore:.*platformdirs.*:DeprecationWarning
# Some pandas FutureWarnings that can be ignored for now:
ignore:.*is_sparse.*:FutureWarning
ignore:.*is_categorical_dtype.*:FutureWarning
ignore:.*swapaxes.*:FutureWarning
# Some numpy DeprecationWarnings:
ignore:.*bool8.*:DeprecationWarning
# DeprecationWarning about pkg_resources (triggered by lifelines):
ignore:.*pkg_resources.*:DeprecationWarning
# Use pytest markers to select/deselect specific tests
markers =
internet: requires internet access
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ python_requires = >=3.7
# new major versions. This works if the required packages follow Semantic Versioning.
# For more information, check out https://semver.org/.
install_requires =
# catboost 1.2+ has build errors on "macos-latest" GH runners: https://github.com/catboost/catboost/issues/2371
catboost < 1.2
clairvoyance2 >=0.0.2
cloudpickle
geomloss>=0.2.6
Expand All @@ -82,8 +80,10 @@ install_requires =
torchdiffeq
torchlaplace >= 0.0.4
tsai
typing-extensions
typing-extensions >= 4.7.1
xgbse
# joblib has a bug with py37 & Windows: https://github.com/joblib/loky/issues/411
joblib < 1.3.0; python_version=="3.7" and platform_system=="Windows"


[options.packages.find]
Expand Down
1 change: 0 additions & 1 deletion src/tempor/benchmarks/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def benchmark_models(

@pydantic.validate_arguments(config=dict(arbitrary_types_allowed=True))
def visualize_benchmark(results: Dict[str, pd.DataFrame], palette: str = "viridis") -> Any:

# Pre-format DF for plotting.
for k, v in results.items():
v["method"] = k
Expand Down
1 change: 0 additions & 1 deletion src/tempor/benchmarks/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ def roc_auc_score(self, y_test: np.ndarray, y_pred_proba: np.ndarray) -> float:
return utils.evaluate_auc_multiclass(y_test, y_pred_proba)[0]

def average_precision_score(self, y_test: np.ndarray, y_pred_proba: np.ndarray) -> float:

return utils.evaluate_auc_multiclass(y_test, y_pred_proba)[1]


Expand Down
2 changes: 0 additions & 2 deletions src/tempor/benchmarks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def evaluate_auc_multiclass(
y_pred_proba_tmp = get_y_pred_proba_hlpr(y_pred_proba, n_classes)

if n_classes > 2:

log.debug(f"+evaluate_auc {y_test.shape} {y_pred_proba_tmp.shape}")

fpr = dict()
Expand All @@ -60,7 +59,6 @@ def evaluate_auc_multiclass(
aucroc = roc_auc["micro"]
aucprc = average_precision["micro"]
else:

aucroc = roc_auc_score(np.ravel(y_test), y_pred_proba_tmp, multi_class="ovr")
aucprc = average_precision_score(np.ravel(y_test), y_pred_proba_tmp)

Expand Down
34 changes: 33 additions & 1 deletion src/tempor/data/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
# pylint: disable=unnecessary-ellipsis

import abc
import contextlib
from typing import TYPE_CHECKING, Any, List, Optional, Tuple

import numpy as np
import pandas as pd
import pandera as pa
import pydantic
from packaging.version import Version
from typing_extensions import Self

import tempor.exc
Expand Down Expand Up @@ -292,6 +294,35 @@ def __getitem__(self, key: data_typing.GetItemKey) -> Self:
)


@contextlib.contextmanager
def workaround_pandera_pd2_1_0_multiindex_compatibility(schema: pa.DataFrameSchema, data: pd.DataFrame):
"""A version compatibility issue exists between pandera and pandas 2.1.0, as reported here:
https://github.com/unionai-oss/pandera/issues/1328

The error pertains to multiindex uniqueness validation giving an unexpected error.

This is a workaround that will "manually" throw an error that is expected from pandera.
"""

def problem_versions() -> bool:
return Version(pd.__version__) >= Version("2.1.0")
# TODO: When/if fixed in pandera, add the below condition:
# and Version(pa.__version__) < Version("0.XX.YY")

try:
yield

except ValueError as ex:
if problem_versions() and "Columns with duplicate values are not supported in stack" in str(ex):
cols = data.index.names
raise pa.errors.SchemaError(schema=schema, data=data, message=f"columns {cols} not unique")
else:
raise

finally:
pass


class TimeSeriesSamples(DataSamples):
_data: pd.DataFrame
_schema: pa.DataFrameSchema
Expand Down Expand Up @@ -397,7 +428,8 @@ def _validate(self) -> None:
coerce=False,
unique=multiindex_unique_def,
)
self._data = schema.validate(data)
with workaround_pandera_pd2_1_0_multiindex_compatibility(schema, data):
self._data = schema.validate(data)

logger.debug(f"Final schema:\n{schema}")
self._schema = schema
Expand Down
1 change: 0 additions & 1 deletion src/tempor/models/ddh.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def __init__(
clipping_value: int = 1,
output_mode: str = "MLP",
) -> None:

self.split = split
self.split_time = None

Expand Down
2 changes: 0 additions & 2 deletions src/tempor/utils/dataloaders/sine.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,13 @@ def load(self, **kwargs) -> dataset.OneOffPredictionDataset:
# Generate sine data.

for i in range(self.no):

# Initialize each time-series
local = list()

# For each feature
seq_len = self.seq_len

for k in range(self.temporal_dim): # pylint: disable=unused-variable

# Randomly drawn frequency and phase:
freq = np.random.beta(2, 2)
phase = np.random.normal()
Expand Down
1 change: 0 additions & 1 deletion tests/automl/test_pipeline_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ def assert_actual_params(pipe, sample, method):
assert getattr(estimator.params, k) == v


@pytest.mark.filterwarnings("ignore:.*bool8.*:DeprecationWarning") # Expected.
@pytest.mark.parametrize("task_type,predictor", TEST_PREDICTOR_CASES)
@pytest.mark.parametrize("static_imputers", TEST_STATIC_IMPUTERS_CASES)
@pytest.mark.parametrize("static_scalers", TEST_STATIC_SCALERS_CASES)
Expand Down
2 changes: 0 additions & 2 deletions tests/automl/test_seeker.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def patched_transform(self, *args, **kwargs): # pylint: disable=unused-argument
np.random.seed(12345)

def patched_evaluate(*args, **kwargs):

# Since "ensure reproducibility" may affect seeding, and we want this function to return different values,
# seed it from input hash manually as below.
seed_from = str(args[0])
Expand Down Expand Up @@ -610,7 +609,6 @@ def test_init_fails_wrong_overrides(self, get_dataset: Callable):
override_hp_space=override_hp_space, # type: ignore
)

@pytest.mark.filterwarnings("ignore:.*bool8.*:DeprecationWarning") # Expected.
@pytest.mark.parametrize(
"task_type,estimator_names,metric",
[
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def func(ds: "dataset.PredictiveDataset") -> "dataset.CovariatesDataset":

# --- Reusable datasets. ---


# Sine data: full.
@pytest.fixture(scope="session")
def _sine_data_full():
Expand Down
1 change: 0 additions & 1 deletion tests/data/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class DFsTest:


def set_up_dfs_test():

# --- Static. ---

categories = ["A", "B", "C"]
Expand Down
3 changes: 0 additions & 3 deletions tests/log/test_custom_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def as_loguru_logs(records: List[Any]) -> str:


def test_console_logging_at_trace(caplog): # noqa: F811

config = tempor.get_config()
config.logging.level = "TRACE"
tempor.configure(config)
Expand All @@ -97,7 +96,6 @@ def test_console_logging_at_trace(caplog): # noqa: F811


def test_console_logging_at_info(caplog): # noqa: F811

config = tempor.get_config()
config.logging.level = "INFO"
tempor.configure(config)
Expand All @@ -121,7 +119,6 @@ def test_console_logging_at_info(caplog): # noqa: F811


def test_console_logging_at_error(caplog): # noqa: F811

config = tempor.get_config()
config.logging.level = "ERROR"
tempor.configure(config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ def test_transform(
assert output.static.dataframe().isna().sum().sum() == 0


@pytest.mark.filterwarnings("ignore:.*Jupyter.*platformdirs.*:DeprecationWarning") # Expected.
@pytest.mark.filterwarnings("ignore:.*bool8.*:DeprecationWarning") # Expected.
@pytest.mark.filterwarnings("ignore:.*nonzero.*0d.*:DeprecationWarning") # Expected for EM imputer.
@pytest.mark.filterwarnings("ignore::RuntimeWarning") # Expected for EM imputer.
@pytest.mark.filterwarnings("ignore::sklearn.exceptions.ConvergenceWarning") # May happen in some cases.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ def test_transform(
assert output.time_series.dataframe().isna().sum().sum() == 0


@pytest.mark.filterwarnings("ignore:.*Jupyter.*platformdirs.*:DeprecationWarning") # Expected.
@pytest.mark.filterwarnings("ignore:.*bool8.*:DeprecationWarning") # Expected.
@pytest.mark.filterwarnings("ignore:.*nonzero.*0d.*:DeprecationWarning") # Expected for EM imputer.
@pytest.mark.filterwarnings("ignore::RuntimeWarning") # Expected for EM imputer.
@pytest.mark.filterwarnings("ignore::sklearn.exceptions.ConvergenceWarning") # May happen in some cases.
Expand Down
1 change: 0 additions & 1 deletion tests/plugins/test_all_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def test_init_success(plugin_fqn):


# DeprecationWarning expected for preprocessing.imputation.temporal.ts_tabular_imputer:
@pytest.mark.filterwarnings("ignore:.*bool8.*:DeprecationWarning")
@pytest.mark.parametrize("plugin_fqn", PLUGIN_FQNS)
def test_sample_hyperparameters(plugin_fqn):
PluginCls = plugin_loader.get_class(plugin_fqn)
Expand Down