Seaborn pairplot() error, OptionError: "No such keys(s): 'mode.use_inf_as_null'", any idea?

19.9k Views Asked by At

I am thrown an error when I am trying to apply searbor pairplot. My full script is easy, and is copied as follows:

import seaborn as sns
import pandas as pd
import numpy as np

# Creating a sample DataFrame
data = {
    'A': np.random.randn(100),
    'B': np.random.randn(100),
    'C': np.random.randn(100),
    'D': np.random.randn(100)
}
df = pd.DataFrame(data)

# Create a pair plot
sns.pairplot(df)

But I am thrown this error:

---------------------------------------------------------------------------
OptionError                               Traceback (most recent call last)
Cell In[26], line 15
     12 df = pd.DataFrame(data)
     14 # Create a pair plot
---> 15 sns.pairplot(df)

File ~/miniforge3/envs/marketing/lib/python3.9/site-packages/seaborn/_decorators.py:46, in _deprecate_positional_args..inner_f(*args, **kwargs)
     36     warnings.warn(
     37         "Pass the following variable{} as {}keyword arg{}: {}. "
     38         "From version 0.12, the only valid positional argument "
   (...)
     43         FutureWarning
     44     )
     45 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 46 return f(**kwargs)

File ~/miniforge3/envs/marketing/lib/python3.9/site-packages/seaborn/axisgrid.py:2126, in pairplot(data, hue, hue_order, palette, vars, x_vars, y_vars, kind, diag_kind, markers, height, aspect, corner, dropna, plot_kws, diag_kws, grid_kws, size)
   2124 diag_kws.setdefault("legend", False)
   2125 if diag_kind == "hist":
-> 2126     grid.map_diag(histplot, **diag_kws)
   2127 elif diag_kind == "kde":
   2128     diag_kws.setdefault("fill", True)

File ~/miniforge3/envs/marketing/lib/python3.9/site-packages/seaborn/axisgrid.py:1478, in PairGrid.map_diag(self, func, **kwargs)
...
--> 121     raise OptionError(f"No such keys(s): {repr(pat)}")
    122 if len(keys) > 1:
    123     raise OptionError("Pattern matched multiple keys")

OptionError: "No such keys(s): 'mode.use_inf_as_null'"

I have tried removing Seaborn, and reinstalled again with the conda command, but the error is the same.

Have anyone encountered this error before?

4

There are 4 best solutions below

1
Matt Pitkin On

This seems to just be an issue with a particular seaborn version that is solved by using seaborn v0.12.2 or above. This can be installed in a conda environment with, e.g.,:

conda install -c conda-forge seaborn=0.12.2
0
Jakhon On

It is due to pandas. For some reason, pandas and seaborn are not getting well. If you uninstall both pandas and seaborn and install only seaborn, the seaborn will automatically install the right pandas it works well with. Thus, your error will go away. At least, that worked for me.

0
Rafeed Rahman On

Just do the following:

pip install --upgrade seaborn
0
Jalil Nourmohammadi Khiarak On

This issue could be specific to your environment or code setup. To troubleshoot further, please consider the following steps:

pip uninstall seaborn matplotlib
pip install seaborn matplotlib

I had issues with the following code:

 sns.distplot(df_benign['mean area'], 
         bins=5, 
         ax=ax[0], 
         label='Benign',
         hist_kws={"hatch": "x"})

I did those step and it worked for me.