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

TypeError ufunc 'isnan' / 'isinf' #199

Open
smarianimore opened this issue Sep 26, 2024 · 2 comments
Open

TypeError ufunc 'isnan' / 'isinf' #199

smarianimore opened this issue Sep 26, 2024 · 2 comments

Comments

@smarianimore
Copy link

Hello,
I'm trying to use causal-learn (pc and fci at the moment) but I'm stuck with input data errors.

My dataframe has no nans nor infs, as checked with both pandas and numpy, but running either algorithm reports error

TypeError: ufunc 'isnan' (or 'isinf') not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

The full stack trace is as follows (where data types can also be seen):

reading csv...
                df.dtypes=cpu_utilization    Float64
memory_usage       Float64
pixel                Int64
fps                  Int64
consumption          Int64
dtype: object
                df.isnull().values.any()=np.False_
                np.isinf(df).values.any()=np.False_
        learning structure...
                df.shape=(12748, 5)
0it [00:00, ?it/s]
Traceback (most recent call last):
  File "/home/stefano/PyCharm-projects/Playground-causal-learn/scripts/tu_wien_stuff.py", line 126, in <module>
    process_file(f"{args.filepath}/{file}", columns, args)
  File "/home/stefano/PyCharm-projects/Playground-causal-learn/scripts/tu_wien_stuff.py", line 81, in process_file
    model = learn_structure(np_data, args.nrows, filepath)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stefano/PyCharm-projects/Playground-causal-learn/scripts/tu_wien_stuff.py", line 46, in learn_structure
    model_graph, model_edges = fci(df, mvpc=True, indep_test="mv_fisherz")  # TODO ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stefano/.pyenv/versions/3.11.3/lib/python3.11/site-packages/causallearn/search/ConstraintBased/FCI.py", line 738, in fci
    independence_test_method = CIT(dataset, method=independence_test_method, **kwargs)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stefano/.pyenv/versions/3.11.3/lib/python3.11/site-packages/causallearn/utils/cit.py", line 32, in CIT
    return FisherZ(data, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stefano/.pyenv/versions/3.11.3/lib/python3.11/site-packages/causallearn/utils/cit.py", line 142, in __init__
    self.assert_input_data_is_valid()
  File "/home/stefano/.pyenv/versions/3.11.3/lib/python3.11/site-packages/causallearn/utils/cit.py", line 81, in assert_input_data_is_valid
    assert allow_nan or not np.isnan(self.data).any(), "Input data contains NaN. Please check."
                            ^^^^^^^^^^^^^^^^^^^
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
@kunwuz
Copy link
Collaborator

kunwuz commented Oct 28, 2024

Hi, if possible, could you please provide a minimal example of code and data to reproduce this error? I haven't got this on my end.

@smarianimore
Copy link
Author

smarianimore commented Nov 8, 2024

Sorry for the latency, here it is a gist with a MWE and example dataset that generates the error: https://gist.github.com/smarianimore/3e78a8ddc5d642b0432c324d495ede22

FYI, in the MWE I'm using causallearn.search.ConstraintBased.PC, but the same error happens with fci.
As an aside, the same MWE but using ges or lingam gives a different error: AttributeError: np.matwas removed in the NumPy 2.0 release. Usenp.asmatrix instead. (I have numpy 2.1.1 installed)

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

No branches or pull requests

2 participants