Skip to content

Fix and test scalar extension dtype op corner case #22378

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
merged 3 commits into from
Aug 18, 2018

Conversation

jbrockmendel
Copy link
Member

Fixes the following behavior in master:

ser = pd.Series(['a', 'b', 'c'])

>>> ser + "category"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pandas/core/ops.py", line 1233, in wrapper
    return dispatch_to_extension_op(op, left, right)
  File "pandas/core/ops.py", line 1163, in dispatch_to_extension_op
    res_values = op(new_left, new_right)
TypeError: can only concatenate list (not "str") to list


>>> ser + "Int64"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pandas/core/ops.py", line 1233, in wrapper
    return dispatch_to_extension_op(op, left, right)
  File "pandas/core/ops.py", line 1163, in dispatch_to_extension_op
    res_values = op(new_left, new_right)
TypeError: can only concatenate list (not "str") to list

and the same for the reversed ops.

@jorisvandenbossche jorisvandenbossche added Bug ExtensionArray Extending pandas with custom dtypes or arrays. labels Aug 16, 2018
Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Good catch :)

@@ -1228,8 +1228,8 @@ def wrapper(left, right):
"{op}".format(typ=type(left).__name__, op=str_rep))

elif (is_extension_array_dtype(left) or
is_extension_array_dtype(right)):
# TODO: should this include `not is_scalar(right)`?
(is_extension_array_dtype(right) and not is_scalar(right))):
Copy link
Member

Choose a reason for hiding this comment

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

Is checking that it is a string a bit more logical?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess that would work. Elsewhere the same check is done with not is_scalar

Copy link
Member

Choose a reason for hiding this comment

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

then ignore my comment and go for consistency

@codecov
Copy link

codecov bot commented Aug 16, 2018

Codecov Report

Merging #22378 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #22378   +/-   ##
=======================================
  Coverage   92.05%   92.05%           
=======================================
  Files         169      169           
  Lines       50709    50709           
=======================================
  Hits        46679    46679           
  Misses       4030     4030
Flag Coverage Δ
#multiple 90.46% <ø> (ø) ⬆️
#single 42.25% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/ops.py 96.71% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 70e6f7c...a1e2042. Read the comment docs.

@jbrockmendel
Copy link
Member Author

@jorisvandenbossche think this is mergeable? I'm looking through the queue for stuff sufficiently small/easy to take off @jreback's plate.

@jorisvandenbossche jorisvandenbossche added this to the 0.24.0 milestone Aug 18, 2018
@jorisvandenbossche jorisvandenbossche merged commit a3e9039 into pandas-dev:master Aug 18, 2018
@jorisvandenbossche
Copy link
Member

Yes, merged, thanks!

Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
@jbrockmendel jbrockmendel deleted the extbug branch April 5, 2020 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants