Skip to content

[Repo Assist] fix(gcm): convert density estimator inputs to float64 for sklearn >= 1.9 compat - #1747

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/fix-density-estimator-int-dtype-sklearn19-20260812-a1508b9b0fb25efc
Draft

[Repo Assist] fix(gcm): convert density estimator inputs to float64 for sklearn >= 1.9 compat#1747
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/fix-density-estimator-int-dtype-sklearn19-20260812-a1508b9b0fb25efc

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This is an automated PR from Repo Assist, an AI assistant for this repository.

Problem

sklearn >= 1.9 changed how BayesianGaussianMixture and KernelDensity handle integer-dtype inputs: score_samples() produces inconsistent or incorrect log-likelihoods when passed int64 arrays. This caused test_anomaly_attribution to fail in CI when sklearn 1.9 is installed (3/3 retries).

Root cause: the anomaly attribution tests pass integer-valued data (e.g. generated from np.random.randint) to GaussianMixtureDensityEstimator, which passes it directly to sklearn without dtype conversion.

Fix

In both GaussianMixtureDensityEstimator and KernelDensityEstimator1D, add .astype(float) to the result of shape_into_2d() before calling sklearn's .fit() and .score_samples(). This ensures float64 input is always passed to sklearn, regardless of the caller's dtype.

This is the same defensive pattern used elsewhere in the GCM codebase (e.g. general.py:116).

Changes

  • dowhy/gcm/density_estimators.py: add .astype(float) in fit() and density() of both GaussianMixtureDensityEstimator and KernelDensityEstimator1D
  • tests/gcm/test_density_estimators.py: add 2 new tests that explicitly pass int64 arrays and assert that density results are finite and positive

Test Status

Tests run on this PR: tests/gcm/test_density_estimators.py — 4 tests (2 existing + 2 new). The environment in CI does not have sklearn 1.9 installed, so the existing tests pass and the new tests guard against future regressions when the lock file is updated.

The fix is a no-op when the input is already float64 (.astype(float) on float64 returns the same array without copying).

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@11c9a2c442e519ff2b427bf58679f5a525353f76

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@11c9a2c442e519ff2b427bf58679f5a525353f76

…1.9 compat

sklearn >= 1.9 changed how BayesianGaussianMixture and KernelDensity handle
integer-dtype inputs — score_samples() produces inconsistent or incorrect
log-likelihoods when passed int64 arrays, causing test_anomaly_attribution to
fail in CI when sklearn 1.9 is installed.

Fix: call .astype(float) on the result of shape_into_2d() in both fit() and
density() methods of GaussianMixtureDensityEstimator and KernelDensityEstimator1D.
This matches sklearn's internal expectation of float64 input and is consistent
with how other GCM modules handle numeric inputs.

Also adds two new tests that explicitly pass int64 arrays to both estimators and
assert that results are finite and positive.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation bug Something isn't working repo-assist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants