Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in ANCOVA function (ValueError: assignment destination is read-only) #421

Open
plankter opened this issue May 8, 2024 · 3 comments
Open
Labels
bug 💥 Something isn't working

Comments

@plankter
Copy link

plankter commented May 8, 2024

Hi,

First, thank you for a very useful library!

With the following versions installed:

Python: 3.12.3
Pingouin: 0.5.4
Pandas: 2.2.2
Numpy: 1.26.4

In the file parametric.py [lines: 1739, 1743] there is a problem with ancova(...) function. This code tries to assign a value to read-only numpy array:

ss_resid = aov["SS"].iloc[-1]
all_effsize = aov["SS"].apply(lambda x: x / (x + ss_resid)).to_numpy()
all_effsize[-1] = np.nan

ValueError: assignment destination is read-only

If one prints flags of all_effsize array with print(all_effsize.flags), the output is the following:

C_CONTIGUOUS : True
F_CONTIGUOUS : True
OWNDATA : False
WRITEABLE : False
ALIGNED : True
WRITEBACKIFCOPY : False

Making a copy of the array before assignment fixes the problem:

all_effsize = all_effsize.copy()
all_effsize[-1] = np.nan

Best regards,
Anton

@raphaelvallat
Copy link
Owner

Hey,

Can you please provide a minimal code example to reproduce the error? I'm not able to reproduce it with the example from Pingouin's documentation.

Can you also please check whether the following works:

ss_resid = aov["SS"].iloc[-1]
all_effsize = aov["SS"].apply(lambda x: x / (x + ss_resid)).to_numpy(copy=True)
all_effsize[-1] = np.nan

If so, please feel free to submit a quick PR.

Thanks,
Raphael

@raphaelvallat raphaelvallat added the bug 💥 Something isn't working label May 25, 2024
@plankter
Copy link
Author

Short update: the issue occurs when the following pandas option is set:

pd.options.mode.copy_on_write = True

Copy-on-Write will be the default and only mode in pandas 3.0

See here: https://pandas.pydata.org/pandas-docs/dev/user_guide/copy_on_write.html#migrating-to-copy-on-write

@raphaelvallat raphaelvallat reopened this Oct 4, 2024
@raphaelvallat
Copy link
Owner

Thanks for the update. I'm re-opening the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 💥 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants