Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas, numpy
ts = pandas.Timestamp('2022-02-01')
dates_sr = pandas.to_datetime(pandas.Series(['2022-01-01', '2022-02-01', '2022-03-01']))
# note that comparison operators work
pandas.testing.assert_series_equal(ts < dates_sr, pandas.Series([False, False, True]))
# numpy.maximum fails
numpy.maximum(ts, dates_sr)
Issue Description
numpy.maximum
fails when given args of type TimeStamp and Series(with dtype datetime64)
Stacktrace follows:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [2], in <module>
2 dates_sr = pandas.to_datetime(pandas.Series(["2022-01-01", "2022-02-01", "2022-03-01"]))
3 pandas.testing.assert_series_equal(ts < dates_sr, pandas.Series([False, False, True]))
----> 4 numpy.maximum(ts, dates_sr)
File ~/.../site-packages/pandas/core/generic.py:2032, in NDFrame.__array_ufunc__(self, ufunc, method, *inputs, **kwargs)
2029 def __array_ufunc__(
2030 self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any
2031 ):
-> 2032 return arraylike.array_ufunc(self, ufunc, method, *inputs, **kwargs)
File ~/.../site-packages/pandas/core/arraylike.py:364, in array_ufunc(self, ufunc, method, *inputs, **kwargs)
361 elif self.ndim == 1:
362 # ufunc(series, ...)
363 inputs = tuple(extract_array(x, extract_numpy=True) for x in inputs)
--> 364 result = getattr(ufunc, method)(*inputs, **kwargs)
365 else:
366 # ufunc(dataframe)
367 if method == "__call__" and not kwargs:
368 # for np.<ufunc>(..) calls
369 # kwargs cannot necessarily be handled block-by-block, so only
370 # take this path if there are no kwargs
TypeError: '>=' not supported between instances of 'Timestamp' and 'int'
Expected Behavior
Expected return value is:
pandas.to_datetime(pandas.Series(['2022-02-01', '2022-02-01', '2022-03-01']))
Installed Versions
INSTALLED VERSIONS
commit : 2e218d1
python : 3.10.2.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-57-generic
Version : #63~20.04.1-Ubuntu SMP Wed Nov 30 13:40:16 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 1.5.3
numpy : 1.24.1
pytz : 2021.3
dateutil : 2.8.2
setuptools : 59.6.0
pip : 22.3.1
Cython : 3.0.0a10
pytest : 7.1.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.2
lxml.etree : 4.7.1
html5lib : None
pymysql : None
psycopg2 : 2.9.3
jinja2 : 3.0.3
IPython : 8.0.1
pandas_datareader: None
bs4 : 4.8.2
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.5.1
numba : None
numexpr : 2.8.1
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : 6.0.1
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.0
snappy : None
sqlalchemy : None
tables : 3.7.0
tabulate : None
xarray : 2022.3.0
xlrd : 1.2.0
xlwt : 1.3.0
zstandard : None
tzdata : 2021.5