From acc7cfec5a88ddb53050ad771ea7753eb6564fd8 Mon Sep 17 00:00:00 2001 From: Stephen Privitera Date: Mon, 26 May 2025 14:09:34 +0200 Subject: [PATCH 1/5] dont require 312 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 58e2759..2815272 100644 --- a/setup.py +++ b/setup.py @@ -28,6 +28,6 @@ "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", ], - python_requires=">=3.12", + python_requires=">=3.9", package_data={"pybalance": ["sim/data/*parquet", "sim/data/*csv"]}, ) From 9ee8d1614605c0ede85f0a21dda9e247d408b6d4 Mon Sep 17 00:00:00 2001 From: Stephen Privitera Date: Mon, 26 May 2025 14:11:12 +0200 Subject: [PATCH 2/5] bump version --- setup.py | 2 +- sphinx/conf.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 2815272..09fff39 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ import setuptools -__version__ = "0.2.1" +__version__ = "0.2.2" with open("README.md", "r") as fh: long_description = fh.read() diff --git a/sphinx/conf.py b/sphinx/conf.py index 959ca0f..516dd13 100644 --- a/sphinx/conf.py +++ b/sphinx/conf.py @@ -26,7 +26,7 @@ copyright = f"2024 - Bayer AG - {author}" # The full version, including alpha/beta/rc tags -release = "0.2.1" +release = "0.2.2" # -- General configuration --------------------------------------------------- From b6df9fd94d3d436915c0d67b36f4e6a35abd7310 Mon Sep 17 00:00:00 2001 From: Stephen Privitera Date: Mon, 26 May 2025 15:01:59 +0200 Subject: [PATCH 3/5] not possible to make torch optional and balance calculators depend on it --- environments/requirements.txt | 3 ++- environments/requirements_genetic.txt | 1 - setup.py | 6 +----- sphinx/conf.py | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) delete mode 100644 environments/requirements_genetic.txt diff --git a/environments/requirements.txt b/environments/requirements.txt index 34d6bdc..899f0ce 100644 --- a/environments/requirements.txt +++ b/environments/requirements.txt @@ -10,4 +10,5 @@ scipy seaborn # the ones below are very particular: keep them set at a fixed version -ortools==9.9.3963 \ No newline at end of file +ortools==9.9.3963 +torch>=2.0.0 \ No newline at end of file diff --git a/environments/requirements_genetic.txt b/environments/requirements_genetic.txt deleted file mode 100644 index e50b93d..0000000 --- a/environments/requirements_genetic.txt +++ /dev/null @@ -1 +0,0 @@ -torch>=2.0.0 \ No newline at end of file diff --git a/setup.py b/setup.py index 09fff39..d9ef844 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ import setuptools -__version__ = "0.2.2" +__version__ = "0.2.3" with open("README.md", "r") as fh: long_description = fh.read() @@ -8,9 +8,6 @@ with open("environments/requirements.txt") as f: requirements = f.read().splitlines() -with open("environments/requirements_genetic.txt") as f: - requirements_genetic = f.read().splitlines() - setuptools.setup( name="pybalance", version=__version__, @@ -19,7 +16,6 @@ description="Population Matching", long_description=long_description, install_requires=requirements, - extras_require={"genetic": requirements_genetic}, long_description_content_type="text/markdown", url="", packages=setuptools.find_packages(), diff --git a/sphinx/conf.py b/sphinx/conf.py index 516dd13..0cb8e36 100644 --- a/sphinx/conf.py +++ b/sphinx/conf.py @@ -26,7 +26,7 @@ copyright = f"2024 - Bayer AG - {author}" # The full version, including alpha/beta/rc tags -release = "0.2.2" +release = "0.2.3" # -- General configuration --------------------------------------------------- From 6d44e5d1477c36d97bbd03c9356bd7c943ab9575 Mon Sep 17 00:00:00 2001 From: Stephen Privitera Date: Wed, 28 May 2025 11:51:31 +0200 Subject: [PATCH 4/5] don't hardcode population column in describe method --- pybalance/utils/matching_data.py | 7 ++++--- pybalance/utils/tests/test_matching_data.py | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pybalance/utils/matching_data.py b/pybalance/utils/matching_data.py index 17323fc..dfe7553 100644 --- a/pybalance/utils/matching_data.py +++ b/pybalance/utils/matching_data.py @@ -330,13 +330,13 @@ def describe_categoric(self, normalize=True) -> pd.DataFrame: for cat in self.headers["categoric"]: tmp = ( self.data.reset_index() - .groupby(["population", cat]) + .groupby([self.population_col, cat]) .count()[["index"]] .reset_index() ) tmp.loc[:, "feature"] = cat tmp = tmp.pivot( - index=["feature", cat], columns=["population"], values=["index"] + index=["feature", cat], columns=[self.population_col], values=["index"] ) tmp.columns = [c[1] for c in tmp.columns] tmp.index.names = ["feature", "value"] @@ -345,8 +345,9 @@ def describe_categoric(self, normalize=True) -> pd.DataFrame: out = pd.concat(out).fillna(0) if normalize: + out = out.astype(float) for c in counts.columns: - out.loc[:, c] = out[c] / counts.iloc[0][c] + out.loc[:, c] = (out[c].values / counts.iloc[0][c]).astype(float) else: out = out.astype(int) diff --git a/pybalance/utils/tests/test_matching_data.py b/pybalance/utils/tests/test_matching_data.py index af49ea1..1cb59a7 100644 --- a/pybalance/utils/tests/test_matching_data.py +++ b/pybalance/utils/tests/test_matching_data.py @@ -222,3 +222,12 @@ def test_specified_headers(): m = MatchingData(df, headers=headers) assert m.headers["categoric"] == [] assert m.headers["numeric"] == ["cat3"] + + +def test_describe_with_custom_population_col(): + # Create a dataset with a custom population column "Z" + data = generate_toy_dataset().data + data.rename(columns={"population": "Z"}, inplace=True) + quantiles = [0, 0.25, 0.5, 0.75, 1] + m = MatchingData(data, population_col="Z") + m.describe(aggregations=[], quantiles=quantiles) From 57e7624940dac15b2d2d7d72631f6589b644c26f Mon Sep 17 00:00:00 2001 From: Stephen Privitera Date: Wed, 28 May 2025 11:55:58 +0200 Subject: [PATCH 5/5] fix build --- .github/workflows/docker-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index c794bee..5c44506 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -23,6 +23,6 @@ jobs: - name: "Black: Code Formatting 👮🏽‍♀️" run: black --diff . && black -v --check . - name: install requirements - run: pip install -r environments/requirements.txt && pip install -r environments/requirements_genetic.txt + run: pip install -r environments/requirements.txt - name: run tests run: PYTHONPATH=. pytest