Skip to content

bug on DatatimeBlock._try_coerce_args() with pandas0.13.0 #6253

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

Closed
wangshun98 opened this issue Feb 4, 2014 · 1 comment
Closed

bug on DatatimeBlock._try_coerce_args() with pandas0.13.0 #6253

wangshun98 opened this issue Feb 4, 2014 · 1 comment

Comments

@wangshun98
Copy link

When running the following example code, it throws error in DatatimeBlock._try_coerce_args()

T1 = pd.to_datetime(pd.Series([ np.nan, datetime(2012,1,1) ]))
T2 = pd.to_datetime(pd.Series([ datetime(2013,1,1), datetime(2012,1,1) ])
T1.where(~T1.isnull(), other=T2)


ValueError Traceback (most recent call last)
in ()
----> 1 T1.where( ~T1.isnull(), other = T2)

C:\Python64\lib\site-packages\pandas\core\generic.pyc in where(self, cond, other, inplace, axis, level, try_cast, raise_on_error)
2887 new_data = self._data.where(other, cond, align=axis is None,
2888 raise_on_error=raise_on_error,
-> 2889 try_cast=try_cast)
2890
2891 return self._constructor(new_data).finalize(self)

C:\Python64\lib\site-packages\pandas\core\internals.pyc in where(self, _args, *_kwargs)
2279
2280 def where(self, _args, *_kwargs):
-> 2281 return self.apply('where', _args, *_kwargs)
2282
2283 def eval(self, _args, *_kwargs):

C:\Python64\lib\site-packages\pandas\core\internals.pyc in apply(self, f, _args, *_kwargs)
2265
2266 else:
-> 2267 applied = getattr(blk, f)(_args, *_kwargs)
2268
2269 if isinstance(applied, list):

C:\Python64\lib\site-packages\pandas\core\internals.pyc in where(self, other, cond, align, raise_on_error, try_cast)
1076 # see if we can operate on the entire block, or need item-by-item
1077 # or if we are a single block (ndim == 1)
-> 1078 result = func(cond, values, other)
1079 if self._can_hold_na or self.ndim == 1:
1080

C:\Python64\lib\site-packages\pandas\core\internals.pyc in func(c, v, o)
1059 return v
1060
-> 1061 v, o = self._try_coerce_args(v, o)
1062 try:
1063 return self._try_coerce_result(

C:\Python64\lib\site-packages\pandas\core\internals.pyc in _try_coerce_args(self, values, other)
1518 values is always ndarra like, other may not be """
1519 values = values.view('i8')
-> 1520 if isnull(other) or (np.isscalar(other) and other == tslib.iNaT):
1521 other = tslib.iNaT
1522 elif isinstance(other, datetime):

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

The issue I found is the "if" condition. When input other is array-like, isnull return and the second "or" condition won't have the same size. A potential fix could be changing line 1520 to:
if np.isscalar(other) and (isnull(other) or other == tslib.iNaT):

@jreback
Copy link
Contributor

jreback commented Feb 4, 2014

was fixed on 0.13.1, IIRC in #5458, #5689

0.13.1 is out (but announcement not yet)

In [5]: T1
Out[5]: 
0          NaT
1   2012-01-01
dtype: datetime64[ns]

In [6]: T2
Out[6]: 
0   2013-01-01
1   2012-01-01
dtype: datetime64[ns]

In [7]: T1.where(~T1.isnull(), other=T2)
Out[7]: 
0   2013-01-01
1   2012-01-01
dtype: datetime64[ns]

@jreback jreback closed this as completed Feb 4, 2014
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

2 participants