Skip to content
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

Binary operations between numeric & categorical should raise #45

Closed
jcrist opened this issue Aug 3, 2017 · 0 comments
Closed

Binary operations between numeric & categorical should raise #45

jcrist opened this issue Aug 3, 2017 · 0 comments

Comments

@jcrist
Copy link
Contributor

jcrist commented Aug 3, 2017

Currently this only happens if the dispatch hits categorical first:

In [21]: df = pd.DataFrame({'x': range(10), 'y': list(map(float, range(10))), 'z': list('abcde')*2})

In [22]: df.z = df.z.astype('category')

In [23]: gdf = gd.DataFrame.from_pandas(df)

In [24]: gdf.x + gdf.z
Out[24]:

 0 144396680282898688
 1               1028
 2                  7
 3                  8
 4                  9
 5                 10
 6                 11
 7                 12
 8                 13
 9                 14

In [25]: gdf.z + gdf.x
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-25-01cf7f26eb92> in <module>()
----> 1 gdf.z + gdf.x

~/Code/pygdf/pygdf/series.py in __add__(self, other)
    356
    357     def __add__(self, other):
--> 358         return self._binaryop(other, 'add')
    359
    360     def __sub__(self, other):

~/Code/pygdf/pygdf/series.py in _binaryop(self, other, fn)
    345         if not isinstance(other, Series):
    346             return NotImplemented
--> 347         return self._impl.binary_operator(fn, self, other)
    348
    349     def _unaryop(self, fn):

~/Code/pygdf/pygdf/categorical.py in binary_operator(self, binop, lhs, rhs)
     73     def binary_operator(self, binop, lhs, rhs):
     74         msg = 'Categorical cannot perform the operation: {}'.format(binop)
---> 75         raise TypeError(msg)
     76
     77     def unary_operator(self, unaryop, series):

TypeError: Categorical cannot perform the operation: add
mike-wendt pushed a commit that referenced this issue Oct 26, 2018
raydouglass pushed a commit that referenced this issue Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant