From 4ebaf59fdaafc9df3a1e1a8b7af9009cde7ef46b Mon Sep 17 00:00:00 2001 From: fernandezfran Date: Mon, 5 Feb 2024 07:56:40 -0300 Subject: [PATCH] fix a bug in the shape of the return in GetDischargeCapacities --- CHANGELOG.md | 6 ++++++ docs/source/tutorials/heuristic_model.ipynb | 2 +- docs/source/tutorials/map-driven_analysis.ipynb | 2 +- galpynostatic/datasets/__init__.py | 6 +++--- galpynostatic/preprocessing.py | 6 +++--- pyproject.toml | 4 ++-- tests/conftest.py | 10 +++++----- tests/test_preprocessing.py | 2 +- 8 files changed, 22 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b726ac..7eac4aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog of galpynostatic +## v0.3.3 (2024-02-05) + +- Fix a bug in the shape of the return of `GetDischargeCapacities` in `preprocessing` module. +- Change the `if/else` condition in the `datasets` submodule by a `try/except` block. + + ## v0.3.2 (2024-01-30) - `base` and `utils` modules are now tested directly. diff --git a/docs/source/tutorials/heuristic_model.ipynb b/docs/source/tutorials/heuristic_model.ipynb index 720f312..d239c73 100644 --- a/docs/source/tutorials/heuristic_model.ipynb +++ b/docs/source/tutorials/heuristic_model.ipynb @@ -472,7 +472,7 @@ } ], "source": [ - "d_new, d_new_err = gp.make_prediction.optimal_particle_size(greg)\n", + "d_new, d_new_err = gp.make_prediction.optimal_particle_size(greg, d0=1e-5)\n", "print(f\"{d_new:.3f} +/- {d_new_err:.3f} micrometers\")" ] }, diff --git a/docs/source/tutorials/map-driven_analysis.ipynb b/docs/source/tutorials/map-driven_analysis.ipynb index 5f0ffdb..856469a 100644 --- a/docs/source/tutorials/map-driven_analysis.ipynb +++ b/docs/source/tutorials/map-driven_analysis.ipynb @@ -81,7 +81,7 @@ } ], "source": [ - "spherical = gp.datasets.load_spherical()\n", + "spherical = gp.datasets.load_dataset(\"spherical\")\n", "greg = gp.model.GalvanostaticRegressor(d=d)\n", "\n", "for m in (\"A\", \"B\"):\n", diff --git a/galpynostatic/datasets/__init__.py b/galpynostatic/datasets/__init__.py index f11e890..accbeb9 100644 --- a/galpynostatic/datasets/__init__.py +++ b/galpynostatic/datasets/__init__.py @@ -67,7 +67,7 @@ def load_dataset(geometry="spherical"): ValueError If the geometry is not `"spherical"`, `"cylindrical"` or `"planar"`. """ - if geometry not in ("spherical", "cylindrical", "planar"): - raise ValueError(f"{geometry} is not a valid geometry.") - else: + try: return pd.read_csv(PATH / f"{geometry}.csv") + except FileNotFoundError: + raise ValueError(f"{geometry} is not a valid geometry.") diff --git a/galpynostatic/preprocessing.py b/galpynostatic/preprocessing.py index 2531c8a..ca29fdb 100644 --- a/galpynostatic/preprocessing.py +++ b/galpynostatic/preprocessing.py @@ -91,7 +91,7 @@ def transform(self, X): Returns ------- - X_new : array-like of shape (n_measurements, 1) + X_new : array-like of shape (n_measurements, ) Discharge capacities in the same order as the ``pandas.DataFrame`` in the input list, but reshaped to fit. """ @@ -110,7 +110,7 @@ def transform(self, X): except IndexError: ... - return X_new.reshape(-1, 1) + return X_new def fit_transform(self, X, y=None, **fit_params): """Transform the curves to discharge capacities with optional params. @@ -130,7 +130,7 @@ def fit_transform(self, X, y=None, **fit_params): Returns ------- - X_new : array-like of shape (n_measurements, 1) + X_new : array-like of shape (n_measurements, ) Discharge capacities in the same order as the ``pandas.DataFrame`` in the input list, but reshaped to fit. """ diff --git a/pyproject.toml b/pyproject.toml index 41024a9..7b720d5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ build-backend = "setuptools.build_meta" [project] name = "galpynostatic" -version = "0.3.2" +version = "0.3.3" authors = [{name = "Francisco Fernandez", email = "ffernandev@gmail.com"}] readme = "README.md" license = {file = "LICENSE"} @@ -40,12 +40,12 @@ classifiers = [ ] urls = { Homepage = "https://github.com/fernandezfran/galpynostatic" } dependencies = [ + "importlib_metadata", "matplotlib", "numpy", "pandas", "scikit-learn", "scipy", - "importlib_metadata", ] [tool.setuptools] diff --git a/tests/conftest.py b/tests/conftest.py index 0089efa..a30a02b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -57,7 +57,7 @@ def nishikawa(): "ref": { "dc": np.array( [0.37869504, 0.3709768, 0.3157027, 0.2755689, 0.19977959] - ).reshape(-1, 1), + ), "dcoeff": 1.0e-9, "k0": 1.0e-6, "dcoeff_err": 2.018390e-10, @@ -141,7 +141,7 @@ def he(): "ref": { "dc": np.array( [159.23154, 153.38335, 135.33395, 104.71328, 55.44732] - ).reshape(-1, 1), + ), "dcoeff": 1.0e-11, "k0": 1.0e-8, "dcoeff_err": 1.804718e-12, @@ -182,7 +182,7 @@ def wang(): "ref": { "dc": np.array( [99.417946, 96.75683, 93.01233, 83.45085, 73.432816, 56.96607] - ).reshape(-1, 1), + ), "dcoeff": 1.0e-8, "k0": 1.0e-6, "dcoeff_err": 3.704666e-09, @@ -230,7 +230,7 @@ def lei(): 3.5315654, 1.6230893, ] - ).reshape(-1, 1), + ), "dcoeff": 1.0e-13, "k0": 1.0e-8, "dcoeff_err": 2.834146e-15, @@ -278,7 +278,7 @@ def bak(): 92.15335, 55.795765, ] - ).reshape(-1, 1), + ), "dcoeff": 1.0e-13, "k0": 1.0e-8, "dcoeff_err": 4.435332e-12, diff --git a/tests/test_preprocessing.py b/tests/test_preprocessing.py index 4a61100..92565c3 100644 --- a/tests/test_preprocessing.py +++ b/tests/test_preprocessing.py @@ -64,4 +64,4 @@ def test_get_discharge_capacities_internal_raise(): gdc = galpynostatic.preprocessing.GetDischargeCapacities(1.0) dc = gdc.fit_transform(dfs) - np.testing.assert_array_almost_equal(dc, [[0]]) + np.testing.assert_array_almost_equal(dc, [0])