-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Changing columns with +=
gives UnboundLocalError
#4996
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
Comments
this is a trivial fix, just define need a test, and I think it makes sense to disable methods that don't make sense on an index
disabling is easy (just set them like in do a PR? |
I'd love to, but I'll probably have to wait till after work tomorrow if there's no rush. |
no problem... |
@jreback I think disabling |
just make that data.index.to_series() // 5 that is an incorrect usage (and the reason these should be disabled!) |
pls also add a note in |
about the |
you fixed iadd? I meant also isub too ( |
Well, fixed insofar as I aliased to add. I'll do isub too. Sent from my iPhone
|
@d10genes sorry..didn't mean the ?. I saw that you fixed iadd, wanted you to add isub (which you just said you are doing)...so good! |
Also, just so I understand you, redefining
|
yep.... |
Ok, I understand, but I don't think subtracting a single string coerces it to an index:
gives a |
that's a bug.....I think go ahead and put it in here (add some tests as well) you can make these wrapped methods if you want to avoid some boilerplate (e.g. have a function factory) lmk |
Ok, but how should the wrapping go? Currently, for my example above you can't do If so, it seems preferable to do an |
no...what I mean is make all of the methods like
|
Ok, I see what you mean. For the |
Something implicit in that wrapper method is that Int64Index (and numerical indices) will no longer do addition the same way. Currently,
gives Is that how it should work? |
Also, this would get rid of the string concatenating behavior that inspired this fix in the first place. |
numpy is doing string summation so that makes sense. I guess do this. Leave you can test what happens in the test suite if you make
which actually make more sense see if lots of things break |
@d10genes after some discussion off-line.....let's leave the existing behavior....its used in places... so just make the change to |
@jreback the other thing we need to do in that exception is to set i=None before everything if hasattr(e, 'args'):
k = res_index[i]
e.args = e.args + ('occurred at index %s' %
com.pprint_thing(k),) Should do if hasattr(e, 'args'):
if i is not None:
k = res_index[i]
e.args = e.args + ('occurred at index %s' %
com.pprint_thing(k),) and change a few lines earlier to: i = None
keys = []
results = {}
if ignore_failures:
successes = []
for i, v in enumerate(series_gen): That way you can always use |
(which, I now understand, is what you meant about the generator producing an error) |
@jtratner can do that in another PR
leave everything else |
@jreback why do you want to disable them? if they don't exist it'll just reassign the variable to the new object, right? |
well, they dont' do the right thing if they are not converted to Index (as |
Changing columns with
+
is fineThe
+=
operator on the other hand correctly changes the columns,but gives an error when trying to display the whole dataframe:
Traceback is here. Not sure if it's an ipython or pandas issue.
pd.__version__ == '0.12.0-371-g1434776'
The text was updated successfully, but these errors were encountered: