Skip to content

BUG: Fix for .str.replace with invalid input #13460

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

Closed
wants to merge 1 commit into from

Conversation

priyankjain
Copy link
Contributor

@priyankjain priyankjain commented Jun 16, 2016

.str.replace now raises TypeError when replacement is invalid

@codecov-io
Copy link

codecov-io commented Jun 16, 2016

Current coverage is 84.28%

Merging #13460 into master will increase coverage by <.01%

@@             master     #13460   diff @@
==========================================
  Files           138        138          
  Lines         50937      50939     +2   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          42934      42936     +2   
  Misses         8003       8003          
  Partials          0          0          

Powered by Codecov. Last updated by d814f43...d5c3f1b

@@ -81,3 +81,4 @@ Performance Improvements

Bug Fixes
~~~~~~~~~
Bug in ``.str.replace`` does not raise when replacement is None (:issue:`13438`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls describe the kind of error, like "does not raise ValueError".

@sinhrks sinhrks added Error Reporting Incorrect or improved errors from pandas Strings String extension data type and string data labels Jun 16, 2016
@sinhrks sinhrks added this to the 0.18.2 milestone Jun 16, 2016
@priyankjain priyankjain force-pushed the 13438 branch 3 times, most recently from 0e398b6 to f4f04e3 Compare June 16, 2016 10:41
return _na_map(f, arr)
return _na_map(f, arr)
else:
raise TypeError("Can't convert {0} object to str implicitly"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put this in the beginning? I (so switch the if/else part, also in that case the else is not needed)
IMO that is an easier to follow logic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Further, I don't find the error message clear. I know this is the one from the stdlib, but a numeric value can be converted to string, so that sounds a bit strange. Maybe just something like "expected a string" or "the replacement argument should be a string"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do said changes, do you know why travis test has not started, it's yellow for around half an hour, no progress.

Copy link
Member

@jorisvandenbossche jorisvandenbossche Jun 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is because there is a queue, and each time you push a new version (or somebody else pushes on his/her PR), one travis build is added to this queue: https://travis-ci.org/pydata/pandas/pull_requests
(but will stop some of your builds)

@priyankjain priyankjain force-pushed the 13438 branch 2 times, most recently from 781b959 to 4079333 Compare June 16, 2016 11:34
@@ -309,6 +309,8 @@ def str_replace(arr, pat, repl, n=-1, case=True, flags=0):
-------
replaced : Series/Index of objects
"""
if not is_string_like(repl): # Check whether repl is valid (GH 13438)
raise TypeError("Replacement should be a string")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about "repl must be a string", to be consistent with docstring.

.str.replace now raises TypeError when replacement string is not string like
@jreback
Copy link
Contributor

jreback commented Jun 16, 2016

thanks @priyankjain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas Strings String extension data type and string data
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ERR: invalid input to .str.replace does not raise
5 participants