-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
ERR: setting a column with a scalar and no index should raise #16823
Comments
I'm not convinced this is a bug... as @jreback says, In [2]: s = pd.Series(range(4))
In [3]: s.loc[5:] = 1 ? I'm pretty sure we want to allow it. On the other hand, in I see instead the incoherence with |
@jreback I invite you to reconsider this. "Fixing" this has really brought no advantage. I wonder whether any real example of "lost information" can be provided, and on the other hand there is an evident loss of generality. It's the equivalent of stating that the expression Perhaps most importantly, this can break perfectly valid code written in the past, as in:
I probably never wrote such code, but there is no reason to punish any user who did. A warning would be acceptable, but then the examples above should raise a warning too for coherence. Anyway, we have had a full |
@toobaz I disagree. This is a clear error, expecting a column to spring into existance and none does. A deprecation cycle is for something that is not necessarily a problem but an api change. this is an error. |
It does instead! It is just empty because the index is empty, but the Again, what is the "error" in the snippet I posted above?! Also consider the example in which pandas is used to automatically process every day some This really reminds me of other cases in which it was decided to do things which were more complicated and less general but apparently more "friendly", just to regret it later (I'm clearly referring to the project in general, not to anybody's decisions in particular). |
... and anyway, if we really made a rule that any expression of the form
with |
I agree with @toobaz general feeling of "why was this actually needed" without seeing a real benefit. We can certainly discuss the validity of the original code example that was changed to raise an error (should one be allowed to assign into an empty series/frame?), but about the current merged PR, IMO it:
|
these should raise as well. I am not against your example, but its non-idiomatic. I don't see why it should work (aside from the fact that you are also setting on a copy) Fundamentally I agree we should align behavior. So I would be willing to reverse this if we then allow scalars in the constructor w/o an Index. But I am afraid that will lead to many errors and is a worse case. |
I think that it would be better than nothing (also because, all else equal, for backward compatibility we prefer to allow than to disallow something new). But frankly speaking, to me things seem relatively simple:
In both cases, scalars/empty indexes represent no exception to the general behavior. If we take your path, we have to also fix |
can u create an issue (and repeat your last there) |
…h no index ( pandas-dev#16823) (pandas-dev#16968)" This reverts commit f9ba6fe.
…h no index ( pandas-dev#16823) (pandas-dev#16968)" (pandas-dev#17902) * Revert "ERR: Raise ValueError when setting scalars in a dataframe with no index ( pandas-dev#16823) (pandas-dev#16968)" This reverts commit f9ba6fe. * TST: expicit test on setting scalars on empty frame closes pandas-dev#17894
…h no index ( pandas-dev#16823) (pandas-dev#16968)" (pandas-dev#17902) * Revert "ERR: Raise ValueError when setting scalars in a dataframe with no index ( pandas-dev#16823) (pandas-dev#16968)" This reverts commit f9ba6fe. * TST: expicit test on setting scalars on empty frame closes pandas-dev#17894
…h no index ( pandas-dev#16823) (pandas-dev#16968)" (pandas-dev#17902) * Revert "ERR: Raise ValueError when setting scalars in a dataframe with no index ( pandas-dev#16823) (pandas-dev#16968)" This reverts commit f9ba6fe. * TST: expicit test on setting scalars on empty frame closes pandas-dev#17894
xref #10017 (comment)
This should raise like [5] below.
Even though this is technically valid code (in [4]), IOW the scalar is reindexed to a 0-len index, this immediately loses information This should raise an error.
The text was updated successfully, but these errors were encountered: