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? Normalize modifies pandas Series inplace #5427
Comments
I'd say it's a bug. There have been similar surprises elsewhere in matplotlib over the years and I think the general consensus is to not mutate passed-in arrays. |
It looks like the problem is in the |
The issue here is that In [25]: tt = pd.Series(np.random.randn(10))
In [26]: mt = ma.asarray(tt)
In [27]: mt[0] = 0
In [31]: tt
Out[31]:
0 0.000000
1 0.367954
2 1.454730
3 -0.322231
4 2.203396
5 -2.031685
6 -0.129424
7 0.099887
8 -0.063291
9 0.123325
dtype: float64 Below we work on |
Does checking |
Oh hey, that 'just works' 👍 |
It looks like that works. I was worried about overhead, but maybe it's OK.
|
Is |
I was also digging into that tring to sort out if lists are re-converted to arrays for this check or if it has a 'this does not support buffer-protocol, stop it' cut-out mode |
Nope:
|
The original version went in to numpy in e122f0798a686a41616908e071531790e84e5414 (2007) but it looks like the version that is compatible with pandas is newer than that fae8369fba4a683783280b044915b11bbca07a44 (2013) which is ~ np 1.8 I think the two options are:
|
My original suggestion was #1, and I think it still looks good. I am not concerned about the performance for lists; they are not likely to be long enough that it matters. There might be other array-like beasts for which we end up with an unnecessary copy, but I don't think it is worth worrying about that now. |
@efiring Done. That rabbit whole almost looked promising (it was not). |
Not sure if this is a bug, but it was surprising.
Strangely, if
s
in a integer series (s = pd.Series(range(10))
), it will not be modified. FWIW, a list of floats aren't modified either.The text was updated successfully, but these errors were encountered: