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

python 3.11.2,matplotlib 3.7.1,seaborn 0.12.2conda update—allat the anaconda prompt