-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Fix Series construction with dtype=str #20401
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
Changes from all commits
9569eb3
a188cf7
1844e6e
55f9998
d6aac90
ba2d2c0
81fde6e
41d35ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4059,9 +4059,10 @@ def _try_cast(arr, take_fast_path): | |
if issubclass(subarr.dtype.type, compat.string_types): | ||
# GH 16605 | ||
# If not empty convert the data to dtype | ||
if not isna(data).all(): | ||
data = np.array(data, dtype=dtype, copy=False) | ||
|
||
subarr = np.array(data, dtype=object, copy=copy) | ||
# GH 19853: If data is a scalar, subarr has already the result | ||
if not is_scalar(data): | ||
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. is this additional check actually needed? (is_scalar) 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. Yes. If it is scalar, no other change is needed, since data = np.array(data, dtype=dtype, copy=False) (That conversion was there already) 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. my point is that do you actually need to add this check? when you take it out (but fix the 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. If I take out, then this https://github.com/pandas-dev/pandas/pull/20401/files#diff-3bbe4551f20de6060dce38a95d0adc80R114 will raise
|
||
if not np.all(isna(data)): | ||
data = np.array(data, dtype=dtype, copy=False) | ||
subarr = np.array(data, dtype=object, copy=copy) | ||
|
||
return subarr |
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.
you don't need all this, just change to use
np.any