-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
replace() alters unrelated values #7140
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
seems to be replacing "truthy" values ... again the dtype issues arise :) |
The docs on replace suggest that, if it's a list, it should be a list of strings... so I'm not sure this is a bug per se. wow, replace really does do a lot! I would definitely consider using one of these instead:
Note: These work with both series and dataframes. |
@hayd : I interpret "list of str, regex, or numeric" as "list of str, list of regex, or list of numeric"... after all,
works as expected (and there is no theoretical reason why it shouldn't). Moreover, "where" does work on dataframes... but I don't see what I am supposed to do with its result, in order to get the result of "replace" (but this may be me temporarily blind). I do understand that a "replace" on a Series of bools may want to filter based on the truthy value, but I'm pretty sure that I want a quick way to replace any numeric value in a DataFrame, without touching booleans. So maybe one possible solution would be to clarify the problem in the docs, and add an argument "subset" as for dropna. Although a cleaner solution would be to add an argument "dtype" which determines the dtype to use for the comparison (i.e. convert booleans to float, not vice versa), and which would have the default value of the series' dtype for a Series, and of the item to be replaced's dtype for a DataFrame with non-homogeneous dtypes. Notice the same problem arises with
|
Good point, that seems like a reasonable interpretation! |
@toobaz while adding those things (kwarg, subset) might make this use case a bit more clear, replace already tries to do too much. In fact we're considering deprecating the replace method (over at least a couple of releases since it's fairly old) into a namespace like we do with |
@toobaz all that said, this IS a bug which will be fixed by the next minor release (0.14.1) |
yep that's the idea, though. i've spent many hours debugging |
I don't know if it is the same bug than #7126 (looks similar, but I didn't check the implementation), but
Notice the operation of doing such a replace on boolean variables may seem stupid... but it is less so if you consider that "replace" (differently from i.e. dropna) does not support a "subset" argument.
The text was updated successfully, but these errors were encountered: