Skip to content

TypeError ufunc 'isnan' / 'isinf' #199

Open
@smarianimore

Description

@smarianimore

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''

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions