Open cauricht opened 2 weeks ago
Issue has only arose after 22 May 2024 - and was current on 26 June However re-running code today (27 June) it works again without trace back error! Even with all packages updated to The version of pandas is 2.2.2 The version of plotnine is 0.13.6 The version of numpy is 2.0.0 The version of matplotlib is 3.9.0 The version of scikit-misc is 0.4.0 The version of statsmodels is 0.14.2
I have the same error with plotnine version 0.13.6 and numpy version 1.26.0. Any suggestions which library is the culprit?
from plotnine import ggplot, aes, geom_point, geom_smooth, labs
from plotnine.data import mpg
(
ggplot(mpg, aes(x="displ", y="hwy"))
+ geom_point()
+ geom_smooth()
+ labs(x="displacement", y="horsepower")
)
import plotnine
print(plotnine.__version__)
Hi Christoph - Greetings from Australia! FYI, I found issue seemed to be inconsistent and specific to geom_smooth loess method.
After digging deeper conflicts may be related to scikit-misc and numpy.
Based on above, I found the following package stack and version combination seems to work and run geom-smooth loess consistently.
The version of pandas is 2.2.2 The version of plotnine is 0.13.6 The version of scikit-misc is 0.3.0 The version of numpy is 1.26.4 The version of matplotlib is 3.8.4
Might be that matplotlib ver 3.9.0 may work in above, but given things are stable and working I've left as above for the moment!
Hope this helps.
Rgds, C
Ah, downgrading to scikit-misc 0.3.0 did the trick! I'll try to keep it this way for the time being as well.
Good to hear it works for you as well. Rgds, C
Description
When using
geom_smooth
with theloess
method, I encounter aTypeError
with the messageasarray() got an unexpected keyword argument 'copy'
. This issue does not occur with other smoothing methods likelm
orlowess
.Reproduction Steps
Here are the steps to reproduce the issue:
Install the required packages:
import pandas as pd import numpy as np from plotnine import ggplot, aes, geom_smooth, labs, theme, element_text
Generate random data
np.random.seed(0) random_data = { 'Date': pd.date_range(start='2020-01-01', periods=300, freq='D'), 'S2_band': np.linspace(400, 2500, 300), 'spec_value': np.sin(np.linspace(0, 20, 300)) + np.random.normal(scale=0.1, size=300), 'Site': ['SDFS_Treat_1']150 + ['SDFS_ref']150 }
random_df = pd.DataFrame(random_data)
Filtered data for the year 2020
filtered_df = random_df[pd.to_datetime(random_df['Date']).dt.year == 2020]
Create the plot with geom_smooth
p = (ggplot(filtered_df, aes(x='S2_band', y='spec_value', color='Site'))
Display the plot
p.show()
Expected behavior
The plot should be generated with geom_smooth using the loess method without any errors.
Actual behavior
A TypeError is raised: TypeError: asarray() got an unexpected keyword argument 'copy' Environment:
Additional context
Other smoothing methods like lm and gam work correctly.
Traceback (most recent call last): File "/env/lib/python3.10/site-packages/plotnine/stats/stat.py", line 306, in fn return cls.compute_panel(pdata, pscales, **params) ... TypeError: asarray() got an unexpected keyword argument 'copy'
Steps Taken to Resolve