0

I am a native R user but need to use Python in a new job. Seaborn objects seems to match up with ggplot much more closely (I know about plotnine; let's ignore it for now).

Unfortunately, it is not working and I cannot find help on the error. The code below is as basic as it gets, and the example was created using trivially modified code taken directly from the SO page.

In my current position we are using a unified Python environment, so my ability to tweak/change/test is severely limited, if not unavailable.

import seaborn as sns
import seaborn.objects as so
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

print("Seaborn version:", sns.__version__)

x_min = 0
x_max = 50
x_len = 25
x = np.linspace(x_min, x_max, x_len)
y = x ** (np.random.rand(x_len))

temp_d = pd.DataFrame(
    {"x": x, "y": y}
)

print(temp_d.head())

plt.scatter(x, y)
so.Plot(
    data = temp_d, x = "x", y = "y"
).add(so.Dots())

I get a "TypeError: data type 'boolean' not understood":

    834         # Process the scale spec for coordinate variables and transform their data
...
---> 97             boolean_vector = vector.dtype in boolean_dtypes
     98         else:
     99             boolean_vector = bool(np.isin(vector, [0, 1, np.nan]).all())

TypeError: data type 'boolean' not understood

I have attached a picture:

enter image description here

Full anonymized trace:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/data/anaconda3/shared/xxxxxxxxxx3.8/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj)
    343             method = get_real_method(obj, self.print_method)
    344             if method is not None:
--> 345                 return method()
    346             return None
    347         else:

/data/anaconda3/shared/xxxxxxxxxx3.8/lib/python3.8/site-packages/seaborn/_core/plot.py in _repr_png_(self)
    277     def _repr_png_(self) -> tuple[bytes, dict[str, float]]:
    278 
--> 279         return self.plot()._repr_png_()
    280 
    281     # TODO _repr_svg_?

/data/anaconda3/shared/xxxxxxxxxx3.8/lib/python3.8/site-packages/seaborn/_core/plot.py in plot(self, pyplot)
    819         """
    820         with theme_context(self._theme_with_defaults()):
--> 821             return self._plot(pyplot)
    822 
    823     def _plot(self, pyplot: bool = False) -> Plotter:

/data/anaconda3/shared/xxxxxxxxxx3.8/lib/python3.8/site-packages/seaborn/_core/plot.py in _plot(self, pyplot)
    834         # Process the scale spec for coordinate variables and transform their data
    835         coord_vars = [v for v in self._variables if re.match(r"^x|y", v)]
--> 836         plotter._setup_scales(self, common, layers, coord_vars)
    837 
    838         # Apply statistical transform(s)

/data/anaconda3/shared/xxxxxxxxxx3.8/lib/python3.8/site-packages/seaborn/_core/plot.py in _setup_scales(self, p, common, layers, variables)
   1217 
   1218             prop = PROPERTIES[prop_key]
-> 1219             scale = self._get_scale(p, scale_key, prop, var_df[var])
   1220 
   1221             if scale_key not in p._variables:

/data/anaconda3/shared/xxxxxxxxxx3.8/lib/python3.8/site-packages/seaborn/_core/plot.py in _get_scale(self, spec, var, prop, values)
   1143                 scale = prop.infer_scale(arg, values)
   1144         else:
-> 1145             scale = prop.default_scale(values)
   1146 
   1147         return scale

/data/anaconda3/shared/xxxxxxxxxx3.8/lib/python3.8/site-packages/seaborn/_core/properties.py in default_scale(self, data)
     65         """Given data, initialize appropriate scale class."""
     66 
---> 67         var_type = variable_type(data, boolean_type="boolean", strict_boolean=True)
     68         if var_type == "numeric":
     69             return Continuous()
/data/anaconda3/shared/xxxxxxxxxx/lib/python3.8/site-packages/seaborn/_core/rules.py in variable_type(vector, boolean_type, strict_boolean)
     95             else:
     96                 boolean_dtypes = ["bool", "boolean"]
---> 97             boolean_vector = vector.dtype in boolean_dtypes
     98         else:
     99             boolean_vector = bool(np.isin(vector, [0, 1, np.nan]).all())
TypeError: data type 'boolean' not understood

UPDATE: These are the package versions I am currently using. I will likely ask our environment administrator to update them.

Matplotlib version: 3.4.3
Numpy version: 1.20.3
Pandas version: 1.3.3
Statsmodels version: 0.12.2
6
  • 4
    Code worked just fine for me. Running seaborn 0.12.2. Commented May 18, 2023 at 20:36
  • 1
    I'm voting to close this issue as not reproducible. Tested in python 3.11.2, matplotlib 3.7.1, seaborn 0.12.2 Commented May 18, 2023 at 21:25
  • 1
    Maybe it depends on the pandas or numpy version? Commented May 19, 2023 at 5:51
  • @TrentonMcKinney, it would not be surprised if you are right. I guess now my question is something closer to "How might I successfully diagnose the error so that I can either fix it on my end or point the package maintainers toward a solution?" Should I modify my question? Commented May 19, 2023 at 12:47
  • 1
    Make sure your packages are updated first. If you’re using anaconda conda update—all at the anaconda prompt Commented May 19, 2023 at 12:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.