Datetime comparisons raise TypeError · Issue #13128 · pandas-dev/pandas (original) (raw)

Comparing a dataframes where some series have a datatype and others a datetime type, yields the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-991045b5f90e> in <module>()
      6 h = pd.DataFrame([['a', 'b'], ['c', 'd']], ['row1', 'row2'])
      7 
----> 8 x != h

/Users/yoshikivazquezbaeza/.virtualenvs/emperor/lib/python2.7/site-packages/pandas/core/ops.pyc in f(self, other)
   1175     def f(self, other):
   1176         if isinstance(other, pd.DataFrame):  # Another DataFrame
-> 1177             return self._compare_frame(other, func, str_rep)
   1178         elif isinstance(other, ABCSeries):
   1179             return self._combine_series_infer(other, func)

/Users/yoshikivazquezbaeza/.virtualenvs/emperor/lib/python2.7/site-packages/pandas/core/frame.pyc in _compare_frame(self, other, func, str_rep)
   3584             raise ValueError('Can only compare identically-labeled '
   3585                              'DataFrame objects')
-> 3586         return self._compare_frame_evaluate(other, func, str_rep)
   3587 
   3588     def _flex_compare_frame(self, other, func, str_rep, level):

/Users/yoshikivazquezbaeza/.virtualenvs/emperor/lib/python2.7/site-packages/pandas/core/frame.pyc in _compare_frame_evaluate(self, other, func, str_rep)
   3564                 return dict([(col, func(a[col], b[col])) for col in a.columns])
   3565 
-> 3566             new_data = expressions.evaluate(_compare, str_rep, self, other)
   3567             return self._constructor(data=new_data, index=self.index,
   3568                                      columns=self.columns, copy=False)

/Users/yoshikivazquezbaeza/.virtualenvs/emperor/lib/python2.7/site-packages/pandas/computation/expressions.pyc in evaluate(op, op_str, a, b, raise_on_error, use_numexpr, **eval_kwargs)
    207     if use_numexpr:
    208         return _evaluate(op, op_str, a, b, raise_on_error=raise_on_error,
--> 209                          **eval_kwargs)
    210     return _evaluate_standard(op, op_str, a, b, raise_on_error=raise_on_error)
    211 

/Users/yoshikivazquezbaeza/.virtualenvs/emperor/lib/python2.7/site-packages/pandas/computation/expressions.pyc in _evaluate_standard(op, op_str, a, b, raise_on_error, **eval_kwargs)
     60     if _TEST_MODE:
     61         _store_test_result(False)
---> 62     return op(a, b)
     63 
     64 

/Users/yoshikivazquezbaeza/.virtualenvs/emperor/lib/python2.7/site-packages/pandas/core/frame.pyc in _compare(a, b)
   3562 
   3563             def _compare(a, b):
-> 3564                 return dict([(col, func(a[col], b[col])) for col in a.columns])
   3565 
   3566             new_data = expressions.evaluate(_compare, str_rep, self, other)

/Users/yoshikivazquezbaeza/.virtualenvs/emperor/lib/python2.7/site-packages/pandas/core/ops.pyc in wrapper(self, other, axis)
    734             if len(self) != len(other):
    735                 raise ValueError('Series lengths must match to compare')
--> 736             return self._constructor(na_op(self.values, other.values),
    737                                      index=self.index, name=name)
    738         elif isinstance(other, pd.DataFrame):  # pragma: no cover

/Users/yoshikivazquezbaeza/.virtualenvs/emperor/lib/python2.7/site-packages/pandas/core/ops.pyc in na_op(x, y)
    707                     y = _index.convert_scalar(x, _values_from_object(y))
    708                 else:
--> 709                     y = y.view('i8')
    710 
    711                 mask = isnull(x)

/Users/yoshikivazquezbaeza/.virtualenvs/emperor/lib/python2.7/site-packages/numpy/core/_internal.pyc in _view_is_safe(oldtype, newtype)
    365 
    366     if newtype.hasobject or oldtype.hasobject:
--> 367         raise TypeError("Cannot change data-type for object array.")
    368     return
    369 

TypeError: Cannot change data-type for object array.

I would expect the result to simply be True.

I would expect the output to be True.

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.9.final.0
python-bits: 64
OS: Darwin
OS-release: 15.4.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8

pandas: 0.18.1
nose: 1.3.7
pip: 1.5.4
setuptools: 21.0.0
Cython: None
numpy: 1.11.0
scipy: 0.17.0
statsmodels: None
xarray: None
IPython: 4.2.0
sphinx: 1.4
patsy: None
dateutil: 2.5.3
pytz: 2016.4
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None