Skip to content

Replace np.asscalar in the dataset feature transformation fallback - #1088

Open
aad1tyaaaaa wants to merge 1 commit into
uber:masterfrom
aad1tyaaaaa:fix-fixed-transformation-asscalar
Open

aad1tyaaaaa wants to merge 1 commit into
uber:masterfrom
aad1tyaaaaa:fix-fixed-transformation-asscalar

Conversation

@aad1tyaaaaa

Copy link
Copy Markdown
Contributor

Proposed changes

_fixed_transformation in causalml/dataset/classification.py uses fs[f_index] and, when the index is past the end of the list, falls back to a random function through np.asscalar(...). np.asscalar was removed in numpy 1.23. make_uplift_classification_logistic reaches this fallback whenever feature_association_list is shorter than n_classification_informative:

make_uplift_classification_logistic(n_samples=200, feature_association_list=["linear"])
# AttributeError: module 'numpy' has no attribute 'asscalar'

This PR indexes with np.random.choice(len(fs)) directly, which draws a single index from the same random stream.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Further comments

The new test test_make_uplift_classification_logistic_with_fewer_associations_than_features in tests/test_datasets.py fails on master with the AttributeError and passes with this change; black is clean.

I used an AI assistant (Claude Code) to help find this bug and write the fix and test. I reviewed and ran everything myself.

_fixed_transformation falls back to a random transformation when the index
is past the end of the function list, which make_uplift_classification_logistic
hits whenever feature_association_list is shorter than
n_classification_informative. The fallback called np.asscalar, removed in
numpy 1.23, so those calls raised AttributeError.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant