From 3e70dfaf75174c4a555f0a1056bfb15dfac17111 Mon Sep 17 00:00:00 2001 From: "quant-ranger[bot]" <132915763+quant-ranger[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 21:44:51 -0500 Subject: [PATCH 1/2] Pre-commit autoupdate (#759) * Pre-commit autoupdate * Hooks --------- Co-authored-by: quant-ranger[bot] <132915763+quant-ranger[bot]@users.noreply.github.com> Co-authored-by: lbittarello Co-authored-by: Marc-Antoine Schmidt --- .pre-commit-config.yaml | 4 ++-- setup.py | 16 +++++++------ src/glum/_distribution.py | 4 +--- src/glum/_glm.py | 23 +++++++++++++------ src/glum_benchmarks/bench_liblinear.py | 8 ++++--- src/glum_benchmarks/cli_run.py | 10 ++++---- src/glum_benchmarks/orig_sklearn_fork/_glm.py | 4 +--- src/glum_benchmarks/util.py | 4 +--- 8 files changed, 41 insertions(+), 32 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ccd5f9fe..acf54485 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,13 +1,13 @@ repos: - repo: https://github.com/Quantco/pre-commit-mirrors-black - rev: 23.12.1 + rev: 24.1.1 hooks: - id: black-conda args: - --safe - --target-version=py39 - repo: https://github.com/Quantco/pre-commit-mirrors-flake8 - rev: 6.1.0 + rev: 7.0.0 hooks: - id: flake8-conda additional_dependencies: [ diff --git a/setup.py b/setup.py index 36d4c53c..67dc24d0 100644 --- a/setup.py +++ b/setup.py @@ -74,9 +74,9 @@ package_dir={"": "src"}, packages=find_packages( where="src", - include=["glum"] - if os.environ.get("CONDA_BUILD") - else ["glum", "glum_benchmarks"], + include=( + ["glum"] if os.environ.get("CONDA_BUILD") else ["glum", "glum_benchmarks"] + ), ), python_requires=">=3.9", install_requires=[ @@ -88,13 +88,15 @@ "scipy", "tabmat>=3.1.0,<4.0.0", ], - entry_points=None - if os.environ.get("CONDA_BUILD") - else """ + entry_points=( + None + if os.environ.get("CONDA_BUILD") + else """ [console_scripts] glm_benchmarks_run = glum_benchmarks.cli_run:cli_run glm_benchmarks_analyze = glum_benchmarks.cli_analyze:cli_analyze - """, + """ + ), ext_modules=cythonize( ext_modules, annotate=False, diff --git a/src/glum/_distribution.py b/src/glum/_distribution.py index 8050e4ab..6b89a0c0 100644 --- a/src/glum/_distribution.py +++ b/src/glum/_distribution.py @@ -956,9 +956,7 @@ def unit_deviance(self, y: np.ndarray, mu: np.ndarray) -> np.ndarray: ------- array-like """ - return 2 * y * (np.arctan(y) - np.arctan(mu)) + np.log( - (1 + mu**2) / (1 + y**2) - ) + return 2 * y * (np.arctan(y) - np.arctan(mu)) + np.log((1 + mu**2) / (1 + y**2)) class BinomialDistribution(ExponentialDispersionModel): diff --git a/src/glum/_glm.py b/src/glum/_glm.py index 39ba0a89..5582b893 100644 --- a/src/glum/_glm.py +++ b/src/glum/_glm.py @@ -2258,11 +2258,15 @@ def _set_up_and_check_fit_args( if any(X.dtypes == "category"): self.feature_names_ = list( chain.from_iterable( - _name_categorical_variables( - dtype.categories, column, getattr(self, "drop_first", False) + ( + _name_categorical_variables( + dtype.categories, + column, + getattr(self, "drop_first", False), + ) + if isinstance(dtype, pd.CategoricalDtype) + else [column] ) - if isinstance(dtype, pd.CategoricalDtype) - else [column] for column, dtype in zip(X.columns, X.dtypes) ) ) @@ -2289,9 +2293,14 @@ def _expand_categorical_penalties(penalty, X, drop_first): return np.array( list( chain.from_iterable( - [elmt for _ in dtype.categories[int(drop_first) :]] - if isinstance(dtype, pd.CategoricalDtype) - else [elmt] + ( + [ + elmt + for _ in dtype.categories[int(drop_first) :] + ] + if isinstance(dtype, pd.CategoricalDtype) + else [elmt] + ) for elmt, dtype in zip(penalty, X.dtypes) ) ) diff --git a/src/glum_benchmarks/bench_liblinear.py b/src/glum_benchmarks/bench_liblinear.py index 2d104e62..252efb4d 100644 --- a/src/glum_benchmarks/bench_liblinear.py +++ b/src/glum_benchmarks/bench_liblinear.py @@ -77,9 +77,11 @@ def liblinear_bench( model_args = dict( penalty=pen, tol=benchmark_convergence_tolerance, - C=1 / (X.shape[0] * alpha) - if reg_multiplier is None - else 1 / (X.shape[0] * alpha * reg_multiplier), + C=( + 1 / (X.shape[0] * alpha) + if reg_multiplier is None + else 1 / (X.shape[0] * alpha * reg_multiplier) + ), # Note that when an intercept is fitted, it is subject to regularization, unlike # other solvers. intercept_scaling helps combat this by inflating the intercept # column, though too low of a value leaves too much regularization and too high diff --git a/src/glum_benchmarks/cli_run.py b/src/glum_benchmarks/cli_run.py index 6bfb9414..b370d63f 100644 --- a/src/glum_benchmarks/cli_run.py +++ b/src/glum_benchmarks/cli_run.py @@ -81,12 +81,14 @@ def cli_run( for Ln in libraries.keys(): click.echo(f"running problem={Pn} library={Ln}") new_params = params.update_params(problem_name=Pn, library_name=Ln) - result, regularization_strength_ = execute_problem_library( + result, _ = execute_problem_library( new_params, iterations, - defaults["diagnostics_level"] - if params.diagnostics_level is None - else params.diagnostics_level, # type: ignore + ( + defaults["diagnostics_level"] # type: ignore + if params.diagnostics_level is None # type: ignore + else params.diagnostics_level # type: ignore + ), ) _save_benchmark_results( output_dir, diff --git a/src/glum_benchmarks/orig_sklearn_fork/_glm.py b/src/glum_benchmarks/orig_sklearn_fork/_glm.py index c521e6fc..00f30f3a 100644 --- a/src/glum_benchmarks/orig_sklearn_fork/_glm.py +++ b/src/glum_benchmarks/orig_sklearn_fork/_glm.py @@ -889,9 +889,7 @@ def unit_variance_derivative(self, mu): return 2 * mu def unit_deviance(self, y, mu): - return 2 * y * (np.arctan(y) - np.arctan(mu)) + np.log( - (1 + mu**2) / (1 + y**2) - ) + return 2 * y * (np.arctan(y) - np.arctan(mu)) + np.log((1 + mu**2) / (1 + y**2)) class BinomialDistribution(ExponentialDispersionModel): diff --git a/src/glum_benchmarks/util.py b/src/glum_benchmarks/util.py index f538a5db..c3e2d5ad 100644 --- a/src/glum_benchmarks/util.py +++ b/src/glum_benchmarks/util.py @@ -409,9 +409,7 @@ def clear_cache(force=False): if cache_location is None: return - cache_size_limit = float( - os.environ.get("GLM_BENCHMARKS_CACHE_SIZE_LIMIT", 1024**3) - ) + cache_size_limit = float(os.environ.get("GLM_BENCHMARKS_CACHE_SIZE_LIMIT", 1024**3)) if force or _get_size_of_cache_directory() > cache_size_limit: shutil.rmtree(cache_location) From 6202d6b5d38f4736ae540008764debd5e2d11e34 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 21:45:09 -0500 Subject: [PATCH 2/2] Bump actions/upload-artifact from 3 to 4 (#743) * Bump actions/upload-artifact from 3 to 4 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3 to 4. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] * Update build_wheels.yml * unique artifact name * download all * add suggestions * Update .github/workflows/build_wheels.yml --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Pavel Zwerschke Co-authored-by: Matthias Schmidtblaicher <42544829+MatthiasSchmidtblaicherQC@users.noreply.github.com> Co-authored-by: Matthias Schmidtblaicher Co-authored-by: Marc-Antoine Schmidt --- .github/workflows/build_wheels.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index c57da7d3..bf8530ec 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -20,9 +20,10 @@ jobs: uses: pypa/cibuildwheel@v2.16.5 env: CIBW_ARCHS_MACOS: x86_64 arm64 - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: path: ./wheelhouse/*.whl + name: wheels-${{ matrix.os }} build_sdist: name: Build source distribution @@ -37,9 +38,10 @@ jobs: run: python -m pip install setuptools setuptools-scm wheel Cython numpy scikit-learn - name: Build sdist run: python setup.py sdist - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: path: dist/*.tar.gz + name: sdist upload_testpypi: if: github.event_name == 'release' && github.event.action == 'published' @@ -51,9 +53,9 @@ jobs: permissions: id-token: write steps: - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: - name: artifact + merge-multiple: true path: dist - uses: pypa/gh-action-pypi-publish@v1.8.11 with: @@ -69,8 +71,8 @@ jobs: permissions: id-token: write steps: - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: - name: artifact path: dist + merge-multiple: true - uses: pypa/gh-action-pypi-publish@v1.8.11