-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: to_numeric should raise if input is more than one dimension #11776 #11780
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
Merged
jreback
merged 1 commit into
pandas-dev:master
from
mortada:to_numeric_should_raise_on_df
Dec 10, 2015
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ def to_timedelta(arg, unit='ns', box=True, errors='raise', coerce=None): | |
|
||
Parameters | ||
---------- | ||
arg : string, timedelta, array of strings (with possible NAs) | ||
arg : string, timedelta, list, tuple, 1-d array, or Series | ||
unit : unit of the arg (D,h,m,s,ms,us,ns) denote the unit, which is an integer/float number | ||
box : boolean, default True | ||
- If True returns a Timedelta/TimedeltaIndex of the results | ||
|
@@ -37,7 +37,7 @@ def to_timedelta(arg, unit='ns', box=True, errors='raise', coerce=None): | |
|
||
def _convert_listlike(arg, box, unit, name=None): | ||
|
||
if isinstance(arg, (list,tuple)) or ((hasattr(arg,'__iter__') and not hasattr(arg,'dtype'))): | ||
if isinstance(arg, (list, tuple)) or not hasattr(arg, 'dtype'): | ||
arg = np.array(list(arg), dtype='O') | ||
|
||
# these are shortcutable | ||
|
@@ -62,8 +62,10 @@ def _convert_listlike(arg, box, unit, name=None): | |
return Series(values, index=arg.index, name=arg.name, dtype='m8[ns]') | ||
elif isinstance(arg, ABCIndexClass): | ||
return _convert_listlike(arg, box=box, unit=unit, name=arg.name) | ||
elif is_list_like(arg): | ||
elif is_list_like(arg) and getattr(arg, 'ndim', 1) == 1: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this extra check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thxs |
||
return _convert_listlike(arg, box=box, unit=unit) | ||
elif getattr(arg, 'ndim', 1) > 1: | ||
raise TypeError('arg must be a string, timedelta, list, tuple, 1-d array, or Series') | ||
|
||
# ...so it must be a scalar value. Return scalar. | ||
return _coerce_scalar_to_timedelta_type(arg, unit=unit, box=box, errors=errors) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that there's no need to check
hasattr(arg,'__iter__')
becauseis_list_like
already checks for thatThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np