-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Description
Summary
Some seaborn plots throw a ValueError depending on the users's global pandas configuration.
Pandas 1.5 introduced a feature called Copy-On-Write (CoW), which aims to lead to more predictable and performant behaviour. CoW is currently an optional setting, which can be controlled with pd.set_option (see example below).
However, CoW it is expected to become the default behaviour in the next version of pandas, and as of the recent launch of pandas v2 it is prominently recommended in the pandas docs . So, I think it is important for seaborn plots work with this setting enabled.
Minimal example
# Minimal example
import pandas as pd
import numpy as np
import seaborn as sns
# Enable CoW
pd.set_option("mode.copy_on_write", True)
# Seaborn displot
data = np.array([1,2,3])
sns.displot(data)Results in error:
File ~/seaborn/distributions.py:497, in _DistributionPlotter.plot_univariate_histogram(self, multiple, element, fill, common_norm, common_bins, shrink, kde, kde_kws, color, legend, line_kws, estimate_kws, **plot_kws)
495 # Pack the histogram data and metadata together
496 edges = edges + (1 - shrink) / 2 * widths
--> 497 widths *= shrink
498 index = pd.MultiIndex.from_arrays([
499 pd.Index(edges, name="edges"),
500 pd.Index(widths, name="widths"),
501 ])
502 hist = pd.Series(heights, index=index, name="heights")
ValueError: output array is read-only
Versions
- seaborn
0.12.2 - matplotlib
3.7.1 - pandas
2.0.0 - numpy
1.23.5
[EDIT: updated example to give full error output]