From c84f5c706ebf011b5d2a23fd0204ef8b4701e104 Mon Sep 17 00:00:00 2001 From: Gabriel Guarisa Date: Mon, 30 Dec 2024 11:58:01 -0300 Subject: [PATCH 1/5] Add add_constant function --- pier_ds_utils/prep.py | 49 +++++++++++++++++++++++++++++++++++++++++++ tests/test_prep.py | 48 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 pier_ds_utils/prep.py create mode 100644 tests/test_prep.py diff --git a/pier_ds_utils/prep.py b/pier_ds_utils/prep.py new file mode 100644 index 0000000..592097e --- /dev/null +++ b/pier_ds_utils/prep.py @@ -0,0 +1,49 @@ +import pandas as pd +import typing + + +def add_constant( + df: typing.Union[pd.DataFrame, pd.Series], + prepend: bool = True, + column_name: str = "const", + constant_value: typing.Any = 1.0, +) -> pd.DataFrame: + """ + Add a constant column to a DataFrame. + + Parameters + ---------- + df : pd.DataFrame + The DataFrame to which the constant column will be added. + prepend : bool, default=True + If True, the constant column will be added as the first column. + If False, the constant column will be added as the last column. + column_name : str, default="const" + The name of the constant column. + constant_value : Any, default=1.0 + The value to be used for the constant column. + + Returns + ------- + pd.DataFrame + The DataFrame with the constant column added. + """ + if not isinstance(df, pd.DataFrame): + raise ValueError("df must be a DataFrame or Series") + + df = df.copy() + + original_column_names = df.columns.tolist() + + df[column_name] = constant_value + + if column_name in original_column_names: + original_column_names.remove(column_name) + + column_names = ( + [column_name] + original_column_names + if prepend + else original_column_names + [column_name] + ) + + return df[column_names] diff --git a/tests/test_prep.py b/tests/test_prep.py new file mode 100644 index 0000000..0545501 --- /dev/null +++ b/tests/test_prep.py @@ -0,0 +1,48 @@ +from pier_ds_utils.prep import add_constant +import pandas as pd +import pytest + + +@pytest.mark.parametrize( + "input_df, prepend, column_name, constant_value, expected_df", + [ + ( + pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}), + True, + "const", + 1.0, + pd.DataFrame({"const": [1.0, 1.0, 1.0], "A": [1, 2, 3], "B": [4, 5, 6]}), + ), + ( + pd.DataFrame({"A": [1, 2, 3], "another_column": [4, 5, 6]}), + True, + "another_column", + 3, + pd.DataFrame({"another_column": [3, 3, 3], "A": [1, 2, 3]}), + ), + ( + pd.DataFrame({"A": [1, 2, 3], "another_column": [4, 5, 6]}), + False, + "another_column", + -1, + pd.DataFrame({"A": [1, 2, 3], "another_column": [-1, -1, -1]}), + ), + ( + pd.DataFrame([{"A": 1, "B": 2}]), + True, + "const", + 1.0, + pd.DataFrame({"const": [1.0], "A": [1], "B": [2]}), + ), + ], +) +def test_add_constant_column( + input_df, prepend, column_name, constant_value, expected_df +): + df_with_const = add_constant( + input_df, + prepend=prepend, + column_name=column_name, + constant_value=constant_value, + ) + assert df_with_const.equals(expected_df) From 1c8070b1e261bda72b4b170d16f12fc3637fd764 Mon Sep 17 00:00:00 2001 From: Gabriel Guarisa Date: Mon, 30 Dec 2024 12:02:00 -0300 Subject: [PATCH 2/5] Change GLMWrapper to use new add_constant_column function --- pier_ds_utils/estimator.py | 9 +++++++-- pier_ds_utils/prep.py | 2 +- tests/test_prep.py | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pier_ds_utils/estimator.py b/pier_ds_utils/estimator.py index 5fd2306..b496c19 100644 --- a/pier_ds_utils/estimator.py +++ b/pier_ds_utils/estimator.py @@ -5,6 +5,7 @@ import statsmodels.api as sm from pier_ds_utils.transformer import BaseCustomTransformer +from pier_ds_utils.prep import add_constant_column from sklearn.base import BaseEstimator @@ -24,7 +25,9 @@ def get_params(self, deep=True): def fit(self, X, y, **fit_params): if self._add_constant: - X = sm.add_constant(X) + X = add_constant_column( + X, prepend=True, constant_value=1.0, column_name="const" + ) self.model_ = sm.GLM(endog=y, exog=X, **self.init_params) fit_method = fit_params.pop("fit_method", "fit") @@ -33,7 +36,9 @@ def fit(self, X, y, **fit_params): def predict(self, X, **predict_params): if self._add_constant: - X = sm.add_constant(X) + X = add_constant_column( + X, prepend=True, constant_value=1.0, column_name="const" + ) return self.results_.predict(exog=X, **predict_params) * self.os_factor diff --git a/pier_ds_utils/prep.py b/pier_ds_utils/prep.py index 592097e..3ecdb69 100644 --- a/pier_ds_utils/prep.py +++ b/pier_ds_utils/prep.py @@ -2,7 +2,7 @@ import typing -def add_constant( +def add_constant_column( df: typing.Union[pd.DataFrame, pd.Series], prepend: bool = True, column_name: str = "const", diff --git a/tests/test_prep.py b/tests/test_prep.py index 0545501..9f3a914 100644 --- a/tests/test_prep.py +++ b/tests/test_prep.py @@ -1,4 +1,4 @@ -from pier_ds_utils.prep import add_constant +from pier_ds_utils.prep import add_constant_column import pandas as pd import pytest @@ -39,7 +39,7 @@ def test_add_constant_column( input_df, prepend, column_name, constant_value, expected_df ): - df_with_const = add_constant( + df_with_const = add_constant_column( input_df, prepend=prepend, column_name=column_name, From 458cf13abb9755b8226cbec65b43658c61930276 Mon Sep 17 00:00:00 2001 From: Gabriel Guarisa Date: Mon, 30 Dec 2024 12:10:54 -0300 Subject: [PATCH 3/5] Replace taskfile with makefile --- .gitignore | 3 +- CONTRIBUTING.md | 15 ++++--- Makefile | 16 +++++++ Taskfile.yaml | 22 ---------- poetry.lock | 112 +++++++++++++++++++++++++++++++++++++++++++----- pyproject.toml | 3 +- 6 files changed, 130 insertions(+), 41 deletions(-) create mode 100644 Makefile delete mode 100644 Taskfile.yaml diff --git a/.gitignore b/.gitignore index 886aafa..2725f4f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ __pycache__ .pytest_cache .ruff_cache .vscode -pytest-coverage.txt \ No newline at end of file +pytest-coverage.txt +.coverage \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fc2498d..83bdb38 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,17 +1,17 @@ # Contributing -## Development +## Development ### Setting up a development environment If you don't have a local development environment, you can follow these steps to set one up. -Install [poetry](https://python-poetry.org/) and [task](https://taskfile.dev/). +Install [poetry](https://python-poetry.org/). Now, initialize the project: ```bash -task init +make init ``` ### Running tests @@ -19,7 +19,7 @@ task init You can run the tests with: ```bash -task tests +make tests ``` This will run the tests with [pytest](https://docs.pytest.org/en/latest/) and show information about the coverage. @@ -27,14 +27,15 @@ This will run the tests with [pytest](https://docs.pytest.org/en/latest/) and sh ### Formatting the code To look for formatting issues: + ```bash -task check-formatting +make check-formatting ``` To format the code, you can use the command: ```bash -task formatting +make formatting ``` ### Releasing a new version @@ -45,4 +46,4 @@ To release a new version, you need to follow these steps: 2. Create a Github release with the new version number. -3. (Optional) Publish the new version to PyPI with `poetry publish --build`. \ No newline at end of file +3. (Optional) Publish the new version to PyPI with `poetry publish --build`. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..071382c --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ + +.PHONY: init +init: + poetry install -n + +.PHONY: tests +tests: + poetry run pytest --cov-report=term-missing:skip-covered --cov=pier_ds_utils tests/ | tee pytest-coverage.txt + +.PHONY: check-formatting +check-formatting: + poetry run ruff check . + +.PHONY: formatting +formatting: + poetry run ruff format . \ No newline at end of file diff --git a/Taskfile.yaml b/Taskfile.yaml deleted file mode 100644 index 9c1b42c..0000000 --- a/Taskfile.yaml +++ /dev/null @@ -1,22 +0,0 @@ -version: 3 - -vars: - DECISIONS_DIR: docs/decisions - -tasks: - init: - desc: initializes the project - cmds: - - poetry install -n - tests: - desc: run automated tests - cmds: - - poetry run pytest tests | tee pytest-coverage.txt - check-formatting: - desc: checks formatting - cmds: - - poetry run ruff check . - formatting: - desc: formats the code - cmds: - - poetry run ruff format . diff --git a/poetry.lock b/poetry.lock index 53b3bde..f933565 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.5 and should not be changed by hand. [[package]] name = "awswrangler" @@ -16,10 +16,7 @@ boto3 = ">=1.20.32,<2.0.0" botocore = ">=1.23.32,<2.0.0" numpy = {version = ">=1.18,<2.0", markers = "python_version < \"3.12\""} packaging = ">=21.1,<24.0" -pandas = [ - {version = ">=1.2.0,<2.1.0", markers = "python_version < \"3.9\""}, - {version = ">=1.2.0,<3.0.0", markers = "python_version >= \"3.9\""}, -] +pandas = {version = ">=1.2.0,<3.0.0", markers = "python_version >= \"3.9\""} pyarrow = ">=7.0.0" typing-extensions = ">=4.4.0,<5.0.0" @@ -74,8 +71,8 @@ files = [ jmespath = ">=0.7.1,<2.0.0" python-dateutil = ">=2.1,<3.0.0" urllib3 = [ - {version = ">=1.25.4,<1.27", markers = "python_version < \"3.10\""}, {version = ">=1.25.4,<2.1", markers = "python_version >= \"3.10\""}, + {version = ">=1.25.4,<1.27", markers = "python_version < \"3.10\""}, ] [package.extras] @@ -92,6 +89,83 @@ files = [ {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, ] +[[package]] +name = "coverage" +version = "7.6.10" +description = "Code coverage measurement for Python" +optional = false +python-versions = ">=3.9" +files = [ + {file = "coverage-7.6.10-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:5c912978f7fbf47ef99cec50c4401340436d200d41d714c7a4766f377c5b7b78"}, + {file = "coverage-7.6.10-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:a01ec4af7dfeb96ff0078ad9a48810bb0cc8abcb0115180c6013a6b26237626c"}, + {file = "coverage-7.6.10-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a3b204c11e2b2d883946fe1d97f89403aa1811df28ce0447439178cc7463448a"}, + {file = "coverage-7.6.10-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:32ee6d8491fcfc82652a37109f69dee9a830e9379166cb73c16d8dc5c2915165"}, + {file = "coverage-7.6.10-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:675cefc4c06e3b4c876b85bfb7c59c5e2218167bbd4da5075cbe3b5790a28988"}, + {file = "coverage-7.6.10-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:f4f620668dbc6f5e909a0946a877310fb3d57aea8198bde792aae369ee1c23b5"}, + {file = "coverage-7.6.10-cp310-cp310-musllinux_1_2_i686.whl", hash = "sha256:4eea95ef275de7abaef630c9b2c002ffbc01918b726a39f5a4353916ec72d2f3"}, + {file = "coverage-7.6.10-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:e2f0280519e42b0a17550072861e0bc8a80a0870de260f9796157d3fca2733c5"}, + {file = "coverage-7.6.10-cp310-cp310-win32.whl", hash = "sha256:bc67deb76bc3717f22e765ab3e07ee9c7a5e26b9019ca19a3b063d9f4b874244"}, + {file = "coverage-7.6.10-cp310-cp310-win_amd64.whl", hash = "sha256:0f460286cb94036455e703c66988851d970fdfd8acc2a1122ab7f4f904e4029e"}, + {file = "coverage-7.6.10-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:ea3c8f04b3e4af80e17bab607c386a830ffc2fb88a5484e1df756478cf70d1d3"}, + {file = "coverage-7.6.10-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:507a20fc863cae1d5720797761b42d2d87a04b3e5aeb682ef3b7332e90598f43"}, + {file = "coverage-7.6.10-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d37a84878285b903c0fe21ac8794c6dab58150e9359f1aaebbeddd6412d53132"}, + {file = "coverage-7.6.10-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a534738b47b0de1995f85f582d983d94031dffb48ab86c95bdf88dc62212142f"}, + {file = "coverage-7.6.10-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0d7a2bf79378d8fb8afaa994f91bfd8215134f8631d27eba3e0e2c13546ce994"}, + {file = "coverage-7.6.10-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:6713ba4b4ebc330f3def51df1d5d38fad60b66720948112f114968feb52d3f99"}, + {file = "coverage-7.6.10-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:ab32947f481f7e8c763fa2c92fd9f44eeb143e7610c4ca9ecd6a36adab4081bd"}, + {file = "coverage-7.6.10-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:7bbd8c8f1b115b892e34ba66a097b915d3871db7ce0e6b9901f462ff3a975377"}, + {file = "coverage-7.6.10-cp311-cp311-win32.whl", hash = "sha256:299e91b274c5c9cdb64cbdf1b3e4a8fe538a7a86acdd08fae52301b28ba297f8"}, + {file = "coverage-7.6.10-cp311-cp311-win_amd64.whl", hash = "sha256:489a01f94aa581dbd961f306e37d75d4ba16104bbfa2b0edb21d29b73be83609"}, + {file = "coverage-7.6.10-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:27c6e64726b307782fa5cbe531e7647aee385a29b2107cd87ba7c0105a5d3853"}, + {file = "coverage-7.6.10-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:c56e097019e72c373bae32d946ecf9858fda841e48d82df7e81c63ac25554078"}, + {file = "coverage-7.6.10-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c7827a5bc7bdb197b9e066cdf650b2887597ad124dd99777332776f7b7c7d0d0"}, + {file = "coverage-7.6.10-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:204a8238afe787323a8b47d8be4df89772d5c1e4651b9ffa808552bdf20e1d50"}, + {file = "coverage-7.6.10-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e67926f51821b8e9deb6426ff3164870976fe414d033ad90ea75e7ed0c2e5022"}, + {file = "coverage-7.6.10-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:e78b270eadb5702938c3dbe9367f878249b5ef9a2fcc5360ac7bff694310d17b"}, + {file = "coverage-7.6.10-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:714f942b9c15c3a7a5fe6876ce30af831c2ad4ce902410b7466b662358c852c0"}, + {file = "coverage-7.6.10-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:abb02e2f5a3187b2ac4cd46b8ced85a0858230b577ccb2c62c81482ca7d18852"}, + {file = "coverage-7.6.10-cp312-cp312-win32.whl", hash = "sha256:55b201b97286cf61f5e76063f9e2a1d8d2972fc2fcfd2c1272530172fd28c359"}, + {file = "coverage-7.6.10-cp312-cp312-win_amd64.whl", hash = "sha256:e4ae5ac5e0d1e4edfc9b4b57b4cbecd5bc266a6915c500f358817a8496739247"}, + {file = "coverage-7.6.10-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:05fca8ba6a87aabdd2d30d0b6c838b50510b56cdcfc604d40760dae7153b73d9"}, + {file = "coverage-7.6.10-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:9e80eba8801c386f72e0712a0453431259c45c3249f0009aff537a517b52942b"}, + {file = "coverage-7.6.10-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a372c89c939d57abe09e08c0578c1d212e7a678135d53aa16eec4430adc5e690"}, + {file = "coverage-7.6.10-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ec22b5e7fe7a0fa8509181c4aac1db48f3dd4d3a566131b313d1efc102892c18"}, + {file = "coverage-7.6.10-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:26bcf5c4df41cad1b19c84af71c22cbc9ea9a547fc973f1f2cc9a290002c8b3c"}, + {file = "coverage-7.6.10-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:4e4630c26b6084c9b3cb53b15bd488f30ceb50b73c35c5ad7871b869cb7365fd"}, + {file = "coverage-7.6.10-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:2396e8116db77789f819d2bc8a7e200232b7a282c66e0ae2d2cd84581a89757e"}, + {file = "coverage-7.6.10-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:79109c70cc0882e4d2d002fe69a24aa504dec0cc17169b3c7f41a1d341a73694"}, + {file = "coverage-7.6.10-cp313-cp313-win32.whl", hash = "sha256:9e1747bab246d6ff2c4f28b4d186b205adced9f7bd9dc362051cc37c4a0c7bd6"}, + {file = "coverage-7.6.10-cp313-cp313-win_amd64.whl", hash = "sha256:254f1a3b1eef5f7ed23ef265eaa89c65c8c5b6b257327c149db1ca9d4a35f25e"}, + {file = "coverage-7.6.10-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:2ccf240eb719789cedbb9fd1338055de2761088202a9a0b73032857e53f612fe"}, + {file = "coverage-7.6.10-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:0c807ca74d5a5e64427c8805de15b9ca140bba13572d6d74e262f46f50b13273"}, + {file = "coverage-7.6.10-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2bcfa46d7709b5a7ffe089075799b902020b62e7ee56ebaed2f4bdac04c508d8"}, + {file = "coverage-7.6.10-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:4e0de1e902669dccbf80b0415fb6b43d27edca2fbd48c74da378923b05316098"}, + {file = "coverage-7.6.10-cp313-cp313t-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3f7b444c42bbc533aaae6b5a2166fd1a797cdb5eb58ee51a92bee1eb94a1e1cb"}, + {file = "coverage-7.6.10-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:b330368cb99ef72fcd2dc3ed260adf67b31499584dc8a20225e85bfe6f6cfed0"}, + {file = "coverage-7.6.10-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:9a7cfb50515f87f7ed30bc882f68812fd98bc2852957df69f3003d22a2aa0abf"}, + {file = "coverage-7.6.10-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:6f93531882a5f68c28090f901b1d135de61b56331bba82028489bc51bdd818d2"}, + {file = "coverage-7.6.10-cp313-cp313t-win32.whl", hash = "sha256:89d76815a26197c858f53c7f6a656686ec392b25991f9e409bcef020cd532312"}, + {file = "coverage-7.6.10-cp313-cp313t-win_amd64.whl", hash = "sha256:54a5f0f43950a36312155dae55c505a76cd7f2b12d26abeebbe7a0b36dbc868d"}, + {file = "coverage-7.6.10-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:656c82b8a0ead8bba147de9a89bda95064874c91a3ed43a00e687f23cc19d53a"}, + {file = "coverage-7.6.10-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:ccc2b70a7ed475c68ceb548bf69cec1e27305c1c2606a5eb7c3afff56a1b3b27"}, + {file = "coverage-7.6.10-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a5e37dc41d57ceba70956fa2fc5b63c26dba863c946ace9705f8eca99daecdc4"}, + {file = "coverage-7.6.10-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:0aa9692b4fdd83a4647eeb7db46410ea1322b5ed94cd1715ef09d1d5922ba87f"}, + {file = "coverage-7.6.10-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:aa744da1820678b475e4ba3dfd994c321c5b13381d1041fe9c608620e6676e25"}, + {file = "coverage-7.6.10-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:c0b1818063dc9e9d838c09e3a473c1422f517889436dd980f5d721899e66f315"}, + {file = "coverage-7.6.10-cp39-cp39-musllinux_1_2_i686.whl", hash = "sha256:59af35558ba08b758aec4d56182b222976330ef8d2feacbb93964f576a7e7a90"}, + {file = "coverage-7.6.10-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:7ed2f37cfce1ce101e6dffdfd1c99e729dd2ffc291d02d3e2d0af8b53d13840d"}, + {file = "coverage-7.6.10-cp39-cp39-win32.whl", hash = "sha256:4bcc276261505d82f0ad426870c3b12cb177752834a633e737ec5ee79bbdff18"}, + {file = "coverage-7.6.10-cp39-cp39-win_amd64.whl", hash = "sha256:457574f4599d2b00f7f637a0700a6422243b3565509457b2dbd3f50703e11f59"}, + {file = "coverage-7.6.10-pp39.pp310-none-any.whl", hash = "sha256:fd34e7b3405f0cc7ab03d54a334c17a9e802897580d964bd8c2001f4b9fd488f"}, + {file = "coverage-7.6.10.tar.gz", hash = "sha256:7fb105327c8f8f0682e29843e2ff96af9dcbe5bab8eeb4b398c6a33a16d80a23"}, +] + +[package.dependencies] +tomli = {version = "*", optional = true, markers = "python_full_version <= \"3.11.0a6\" and extra == \"toml\""} + +[package.extras] +toml = ["tomli"] + [[package]] name = "exceptiongroup" version = "1.2.0" @@ -223,8 +297,8 @@ files = [ [package.dependencies] numpy = [ - {version = ">=1.20.3", markers = "python_version < \"3.10\""}, {version = ">=1.21.0", markers = "python_version >= \"3.10\" and python_version < \"3.11\""}, + {version = ">=1.20.3", markers = "python_version < \"3.10\""}, {version = ">=1.23.2", markers = "python_version >= \"3.11\""}, ] python-dateutil = ">=2.8.2" @@ -357,6 +431,24 @@ tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} [package.extras] testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] +[[package]] +name = "pytest-cov" +version = "6.0.0" +description = "Pytest plugin for measuring coverage." +optional = false +python-versions = ">=3.9" +files = [ + {file = "pytest-cov-6.0.0.tar.gz", hash = "sha256:fde0b595ca248bb8e2d76f020b465f3b107c9632e6a1d1705f17834c89dcadc0"}, + {file = "pytest_cov-6.0.0-py3-none-any.whl", hash = "sha256:eee6f1b9e61008bd34975a4d5bab25801eb31898b032dd55addc93e96fcaaa35"}, +] + +[package.dependencies] +coverage = {version = ">=7.5", extras = ["toml"]} +pytest = ">=4.6" + +[package.extras] +testing = ["fields", "hunter", "process-tests", "pytest-xdist", "virtualenv"] + [[package]] name = "python-dateutil" version = "2.8.2" @@ -577,8 +669,8 @@ files = [ [package.dependencies] numpy = [ - {version = ">=1.18,<2", markers = "python_version != \"3.10\" or platform_system != \"Windows\" or platform_python_implementation == \"PyPy\""}, {version = ">=1.22.3,<2", markers = "python_version == \"3.10\" and platform_system == \"Windows\" and platform_python_implementation != \"PyPy\""}, + {version = ">=1.18,<2", markers = "python_version != \"3.10\" or platform_system != \"Windows\" or platform_python_implementation == \"PyPy\""}, ] packaging = ">=21.3" pandas = ">=1.0,<2.1.0 || >2.1.0" @@ -669,5 +761,5 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.0" -python-versions = ">=3.8,<3.12" -content-hash = "ab6c6b02595c16981d9be67804208434c6714605a88613920f34c88578bdcaff" +python-versions = ">=3.9,<3.12" +content-hash = "11f32d2f2b14b21e53a48553003f765ee0b64d370317898e00dec793a3cd899c" diff --git a/pyproject.toml b/pyproject.toml index 108ca48..fd4d6d1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ authors = ["caiodallaqua ", "Gabriel Guarisa Date: Mon, 30 Dec 2024 12:12:25 -0300 Subject: [PATCH 4/5] Add test for exception handling --- tests/test_prep.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_prep.py b/tests/test_prep.py index 9f3a914..e600185 100644 --- a/tests/test_prep.py +++ b/tests/test_prep.py @@ -46,3 +46,11 @@ def test_add_constant_column( constant_value=constant_value, ) assert df_with_const.equals(expected_df) + + +def test_add_constant_column_with_wrong_input_type(): + with pytest.raises(ValueError): + add_constant_column("not a DataFrame") + + with pytest.raises(ValueError): + add_constant_column(pd.Series([1, 2, 3])) From d1bbe6d11adaf13e1dd3b08c05ab13c5ae83609d Mon Sep 17 00:00:00 2001 From: Gabriel Guarisa Date: Mon, 30 Dec 2024 12:12:49 -0300 Subject: [PATCH 5/5] v0.4.0 --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fd4d6d1..c5261ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,8 @@ [tool.poetry] name = "pier-ds-utils" -version = "0.3.0" +version = "0.4.0" description = "A library for data science teams to avoid code duplication in common tasks involving scikit-learn transformers and estimators." -authors = ["caiodallaqua ", "Gabriel Guarisa "] +authors = ["Gabriel Guarisa "] readme = "README.md" [tool.poetry.dependencies]