Skip to content

Conversation

@00helloworld
Copy link
Contributor

@00helloworld 00helloworld commented Jul 23, 2025

Final predictions deviate from training outcomes despite identical input data.
During prediction, the branching logic fails to recognize np.number-type values (e.g., np.float32, np.int64) as numerical features. This occurs because the type check isinstance(v, int) or isinstance(v, float) ignores NumPy numeric types.
isinstance(v, (int, float, np.number)) recognizes:
Python natives: int, float
NumPy types: np.int16/32/64, np.float16/32/64
Pandas-backed: pd.Int8Dtype, etc.

Proposed changes

Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue.

Types of changes

What types of changes does your code introduce to CausalML?
Put an x in the boxes that apply

  • 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

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • 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

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc. This PR template is adopted from appium.

fix with isinstance(v, (int, float, np.number)): to take np.number under consideration
@CLAassistant
Copy link

CLAassistant commented Jul 23, 2025

CLA assistant check
All committers have signed the CLA.

@jeongyoonlee jeongyoonlee added the bug Something isn't working label Sep 5, 2025
@jeongyoonlee jeongyoonlee requested a review from Copilot September 5, 2025 16:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug where uplift tree classification fails during prediction when dealing with NumPy numeric types. The issue occurs because the type checking logic only recognizes Python's native int and float types, causing incorrect branching behavior for NumPy arrays with types like np.float32 or np.int64.

  • Updated isinstance checks to include np.number in addition to int and float
  • Fixed type recognition in both classifyWithoutMissingData and classifyWithMissingData functions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@jeongyoonlee
Copy link
Collaborator

Thanks for catching this, @00helloworld.

In this case, it'd be cleaner to use isinstance(v, numbers.Number). Can you update the PR?

In [1]: import numpy as np

In [2]: a = np.array([1.], dtype=np.float32)

In [3]: isinstance(a[0], int), isinstance(a[0], float), isinstance(a[0], np.number)
Out[3]: (False, False, True)

In [4]: import numbers

In [5]: isinstance(a[0], numbers.Number)
Out[5]: True

@00helloworld
Copy link
Contributor Author

Thanks for catching this, @00helloworld.

In this case, it'd be cleaner to use isinstance(v, numbers.Number). Can you update the PR?

In [1]: import numpy as np

In [2]: a = np.array([1.], dtype=np.float32)

In [3]: isinstance(a[0], int), isinstance(a[0], float), isinstance(a[0], np.number)
Out[3]: (False, False, True)

In [4]: import numbers

In [5]: isinstance(a[0], numbers.Number)
Out[5]: True

Thanks for reminding. Updated in a new PR #849

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants