Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numpy iterable import in _causal_analysis.py for numpy>2.0 #945

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

imatiach-msft
Copy link
Contributor

With new numpy 2.0 update the numpy.lib.function_base namespace has become private.
If you try to import it you get the error:

    raise AttributeError(
AttributeError: numpy.lib.function_base is now private. If you are using a public function, it should be available in the main numpy namespace, otherwise check the NumPy 2.0 migration guide.

In econml this throws the exception:

/usr/share/miniconda/envs/test/lib/python3.9/site-packages/responsibleai/managers/causal_manager.py:10: in <module>
    from econml.solutions.causal_analysis import CausalAnalysis
/usr/share/miniconda/envs/test/lib/python3.9/site-packages/econml/solutions/causal_analysis/__init__.py:4: in <module>
    from ._causal_analysis import CausalAnalysis
/usr/share/miniconda/envs/test/lib/python3.9/site-packages/econml/solutions/causal_analysis/_causal_analysis.py:13: in <module>
    from numpy.lib.function_base import iterable
E   ModuleNotFoundError: No module named 'numpy.lib.function_base'

The fix is to import the function from numpy directly, which is also backwards compatible.

Copy link
Collaborator

@kbattocchi kbattocchi left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@imatiach-msft
Copy link
Contributor Author

@kbattocchi it looks like one of the checks to build documentation is failing, preventing a merge:
https://github.com/py-why/EconML/actions/runs/12697247100/job/35393115771?pr=945
can that build be re-tried? I don't have permissions to re-try it. Otherwise, maybe there is some issue with the documentation build that needs to be fixed.

@kbattocchi
Copy link
Collaborator

@imatiach-msft The documentation problem is unrelated to your change; I'm working on a fix and will merge it into your PR once it's in, and then will merge your PR as well, you don't need to do anything further.

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.

2 participants