[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
Conversation
…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>
78 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated PR from Repo Assist, an AI assistant for this repository.
Problem
sklearn >= 1.9changed howBayesianGaussianMixtureandKernelDensityhandle integer-dtype inputs:score_samples()produces inconsistent or incorrect log-likelihoods when passedint64arrays. This causedtest_anomaly_attributionto 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) toGaussianMixtureDensityEstimator, which passes it directly to sklearn without dtype conversion.Fix
In both
GaussianMixtureDensityEstimatorandKernelDensityEstimator1D, add.astype(float)to the result ofshape_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)infit()anddensity()of bothGaussianMixtureDensityEstimatorandKernelDensityEstimator1Dtests/gcm/test_density_estimators.py: add 2 new tests that explicitly passint64arrays and assert that density results are finite and positiveTest 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).