pingouin icon indicating copy to clipboard operation
pingouin copied to clipboard

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

Open plankter opened this issue 9 months ago • 3 comments

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

plankter avatar May 08 '24 10:05 plankter