Skip to content

TypeError: ufunc 'isfinite' not supported with numpy 1.24.0 #3192

@Rizwan-Hasan

Description

@Rizwan-Hasan

This is the code that I ran

import matplotlib.pyplot as plt
import seaborn as sns

fmri = sns.load_dataset("fmri")
fmri.info()

sns.set(style="darkgrid")
sns.lineplot(data=fmri, x="timepoint", y="signal", hue="region", style="event")

plt.show()

This is the error I got

python3 example.py   
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1064 entries, 0 to 1063
Data columns (total 5 columns):
 #   Column     Non-Null Count  Dtype  
---  ------     --------------  -----  
 0   subject    1064 non-null   object 
 1   timepoint  1064 non-null   int64  
 2   event      1064 non-null   object 
 3   region     1064 non-null   object 
 4   signal     1064 non-null   float64
dtypes: float64(1), int64(1), object(3)
memory usage: 41.7+ KB
Traceback (most recent call last):
  File "/home/rizwan/Downloads/Seaborn-Issue/example.py", line 8, in <module>
    sns.lineplot(
  File "/home/rizwan/Miniconda3/envs/py39/lib/python3.9/site-packages/seaborn/relational.py", line 645, in lineplot
    p.plot(ax, kwargs)
  File "/home/rizwan/Miniconda3/envs/py39/lib/python3.9/site-packages/seaborn/relational.py", line 489, in plot
    func(
  File "/home/rizwan/Miniconda3/envs/py39/lib/python3.9/site-packages/matplotlib/__init__.py", line 1423, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/home/rizwan/Miniconda3/envs/py39/lib/python3.9/site-packages/matplotlib/axes/_axes.py", line 5367, in fill_between
    return self._fill_between_x_or_y(
  File "/home/rizwan/Miniconda3/envs/py39/lib/python3.9/site-packages/matplotlib/axes/_axes.py", line 5272, in _fill_between_x_or_y
    ind, dep1, dep2 = map(
  File "/home/rizwan/Miniconda3/envs/py39/lib/python3.9/site-packages/numpy/ma/core.py", line 2360, in masked_invalid
    return masked_where(~(np.isfinite(getdata(a))), a, copy=copy)
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Environment

  • Python 3.9.15
  • Seaborn 0.12.1
  • Matplotlib 3.6.2
  • Pandas 1.5.2
  • Numpy 1.24.0

This error only occurs when I use numpy 1.24.0, version 1.23.5 or lower works as usual.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions