Skip to content

More NA handling in binary ops with object Series #737

@wesm

Description

@wesm
>>> y = [Decimal('1.3'), Decimal('2.3')]
>>> y2 = [datetime.date(2012,1,1), datetime.date(2012,1,2)]
>>> y3 = Series(y, index=y2)


In [21]: y3 + y3.shift(1)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/home/wesm/code/pandas/<ipython-input-21-9b098b74978c> in <module>()
----> 1 y3 + y3.shift(1)

/home/wesm/code/pandas/pandas/core/series.py in wrapper(self, other)
     52             if self.index.equals(other.index):
     53                 name = _maybe_match_name(self, other)
---> 54                 return Series(op(self.values, other.values), index=self.index,
     55                               name=name)
     56 

TypeError: unsupported operand type(s) for +: 'Decimal' and 'float'


In [17]: s = Series(['foo', 'bar', 'baz', np.nan])

In [18]: s
Out[18]: 
0    foo
1    bar
2    baz
3    NaN

In [19]: 'prefix_' + s
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/home/wesm/code/pandas/<ipython-input-19-64e88cc97e2c> in <module>()
----> 1 'prefix_' + s

/home/wesm/code/pandas/pandas/core/series.py in wrapper(self, other)
     65         else:
     66             # scalars

---> 67             return Series(op(self.values, other), index=self.index,
     68                           name=self.name)
     69     return wrapper

/home/wesm/code/pandas/pandas/core/series.py in _radd_compat(left, right)
     73     # GH #353, NumPy 1.5.1 workaround

     74     try:
---> 75         output = radd(left, right)
     76     except TypeError:
     77         cond = (_np_version_under1p6 and

/home/wesm/code/pandas/pandas/core/series.py in <lambda>(x, y)
     70 
     71 def _radd_compat(left, right):
---> 72     radd = lambda x, y: y + x
     73     # GH #353, NumPy 1.5.1 workaround

     74     try:

TypeError: cannot concatenate 'str' and 'float' objects

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions