Timestamp cannot be compared to np.int64: impact on series binary operations · Issue #8058 · pandas-dev/pandas (original) (raw)

Binary operations between two series fail if the .name attribute of the first is a Timestamp and the .name of the second is a numpy.int64.
It seems a corner case, but it's pretty common when the series are slices of dataframes.
It happens independently if, say, + or .add() is used.
It doesn't happen if the order is reversed.
I guess it boils down to Timestamps not having a sufficiently wide equal method.

In [1]: import pandas as pd

In [2]: pd.__version

AttributeError Traceback (most recent call last) in () ----> 1 pd.__version

AttributeError: 'module' object has no attribute '__version'

In [3]: df = pd.DataFrame(randn(5,2))

In [4]: a = df[0]

In [5]: b = pd.Series(randn(5))

In [6]: b.name = pd.Timestamp('2000-01-01')

In [7]: a / b Out[7]: 0 -1.019117 1 -1.455596 2 0.716716 3 -0.052173 4 -10.725603 dtype: float64

In [8]: b / a

TypeError Traceback (most recent call last) in () ----> 1 b / a

/home/ldeleo/venv/test/lib/python2.7/site-packages/pandas/core/ops.pyc in wrapper(left, right, name) 488 if isinstance(rvalues, pd.Series): 489 rindex = getattr(rvalues,'index',rvalues) --> 490 name = _maybe_match_name(left, rvalues) 491 lvalues = getattr(lvalues, 'values', lvalues) 492 rvalues = getattr(rvalues, 'values', rvalues)

/home/ldeleo/venv/test/lib/python2.7/site-packages/pandas/core/common.pyc in _maybe_match_name(a, b) 2927 a_name = getattr(a, 'name', None) 2928 b_name = getattr(b, 'name', None) -> 2929 if a_name == b_name: 2930 return a_name 2931 return None

/home/ldeleo/venv/test/lib/python2.7/site-packages/pandas/tslib.so in pandas.tslib._Timestamp.richcmp (pandas/tslib.c:12147)()

TypeError: Cannot compare type 'Timestamp' with type 'int64'