erdogant / pca

pca: A Python Package for Principal Component Analysis.
https://erdogant.github.io/pca
MIT License
284 stars 42 forks source link

model.biplot() error when pd.options.mode.copy_on_write = True #49

Open FlorinAndrei opened 1 year ago

FlorinAndrei commented 1 year ago

Python 3.11.4 Pandas 2.0.3 pca 2.0.3

Code:

from sklearn.datasets import load_wine
import pandas as pd
from pca import pca

pd.options.mode.copy_on_write = True

data = load_wine()
df = pd.DataFrame(index=data.target, data=data.data, columns=data.feature_names)
model = pca(normalize=True, detect_outliers=['ht2', 'spe'], n_std=2)
results = model.fit_transform(df)

model.biplot(SPE=False, HT2=True, density=True)

Results:

ValueError: assignment destination is read-only

Fixed code (no errors):

pd.options.mode.copy_on_write = False
model.biplot(SPE=False, HT2=True, density=True)
pd.options.mode.copy_on_write = True
erdogant commented 11 months ago

Thank you for mentioning this! I have not seen this error before. Does this happen because your machine (or server) does not have writing rights to disk?

FlorinAndrei commented 11 months ago

No, there are several libraries impacted by this bug. Perhaps your library is just triggering it in a downstream library, I'm not sure.

Anyway, pd.options.mode.copy_on_write = True seems to trigger some kind of bug in Seaborn and other libs. I am simply reporting it where I see it. Copy on write is a very useful feature, recently introduced in Pandas, and I would prefer to be able to keep it enabled without having issues with various libraries out there.

erdogant commented 11 months ago

Good to know! Thanks!