py-why / py-why/causal-learn

TypeError ufunc 'isnan' / 'isinf'

Open
#199 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.7k
Forks
274
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure using the dataframe types and call path shown in the report. Start with causallearn/utils/cit.py and the FCI.py entry point, focusing on input validation around np.isnan. Done means the reported input is handled according to the project's expected validation behavior and a regression test covers the failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, pandas, python
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.