diff --git a/CHANGES b/CHANGES index e2a71d46..71fd2912 100644 --- a/CHANGES +++ b/CHANGES @@ -26,6 +26,10 @@ Changes Enhancements - Add a TI estimator using gaussian quadrature to calculate the free energy. (issue #302, PR #304) + - Warning issued when the series is `None` for `statistical_inefficiency` + (issue #337, PR #338) + - ValueError issued when `df` and `series` for `statistical_inefficiency` + doesn't have the same length (issue #337, PR #338) 22/06/2023 xiki-tempula diff --git a/environment.yml b/environment.yml index 7699f270..025ff953 100644 --- a/environment.yml +++ b/environment.yml @@ -10,3 +10,4 @@ dependencies: - scikit-learn - pyarrow - matplotlib +- loguru diff --git a/readthedocs.yml b/readthedocs.yml index 71851b19..0c61d50f 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -13,7 +13,7 @@ build: python: "mambaforge-4.10" conda: - environment: environment.yml + environment: devtools/conda-envs/test_env.yaml python: install: diff --git a/src/alchemlyb/preprocessing/subsampling.py b/src/alchemlyb/preprocessing/subsampling.py index 4633a87e..92813375 100644 --- a/src/alchemlyb/preprocessing/subsampling.py +++ b/src/alchemlyb/preprocessing/subsampling.py @@ -363,6 +363,15 @@ def _prepare_input(df, series, drop_duplicates, sort): series : Series Formatted Series. """ + if series is None: + warnings.warn( + "The series input is `None`, would not subsample according to statistical inefficiency." + ) + + elif len(df) != len(series): + raise ValueError( + f"The length of df ({len(df)}) should be same as the length of series ({len(series)})." + ) if _check_multiple_times(df): if drop_duplicates: df, series = _drop_duplicates(df, series) diff --git a/src/alchemlyb/tests/test_preprocessing.py b/src/alchemlyb/tests/test_preprocessing.py index b59f66b4..d64c7267 100644 --- a/src/alchemlyb/tests/test_preprocessing.py +++ b/src/alchemlyb/tests/test_preprocessing.py @@ -544,3 +544,16 @@ def test_statistical_inefficiency(self, caplog, u_nk): assert "Running statistical inefficiency analysis." in caplog.text assert "Statistical inefficiency:" in caplog.text assert "Number of uncorrelated samples:" in caplog.text + + +def test_unequil_input(dHdl): + with pytest.raises(ValueError, match="should be same as the length of series"): + statistical_inefficiency(dHdl, series=dHdl[:10]) + + +def test_series_none(dHdl): + with pytest.warns( + UserWarning, + match="The series input is `None`, would not subsample according to statistical inefficiency.", + ): + statistical_inefficiency(dHdl, series=None)