Skip to content
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

DataFrame(Timestamp) add Timedelta fails #22005

Closed
holymonson opened this issue Jul 21, 2018 · 0 comments

Comments

Projects
None yet
3 participants
@holymonson
Copy link
Contributor

commented Jul 21, 2018

Code Sample, a copy-pastable example if possible

pd.DataFrame([pd.Timestamp('2018')]) + pd.Timedelta('1d')
# Traceback (most recent call last):
#   File "/usr/local/lib/python3.6/site-packages/pandas/core/internals.py", line 1355, in eval
#     transf(values), other)
#   File "/usr/local/lib/python3.6/site-packages/pandas/core/internals.py", line 2723, in _try_coerce_args
#     raise TypeError
# TypeError

# During handling of the above exception, another exception occurred:

# Traceback (most recent call last):
#   File "/usr/local/lib/python3.6/site-packages/pandas/core/ops.py", line 1497, in na_op
#     result = expressions.evaluate(op, str_rep, x, y, **eval_kwargs)
#   File "/usr/local/lib/python3.6/site-packages/pandas/core/computation/expressions.py", line 205, in evaluate
#     return _evaluate(op, op_str, a, b, **eval_kwargs)
#   File "/usr/local/lib/python3.6/site-packages/pandas/core/computation/expressions.py", line 65, in _evaluate_standard
#     return op(a, b)
# TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and 'Timedelta'

# During handling of the above exception, another exception occurred:

# Traceback (most recent call last):
#   File "/usr/local/lib/python3.6/site-packages/pandas/core/internals.py", line 1415, in eval
#     result = get_result(other)
#   File "/usr/local/lib/python3.6/site-packages/pandas/core/internals.py", line 1383, in get_result
#     result = func(values, other)
#   File "/usr/local/lib/python3.6/site-packages/pandas/core/ops.py", line 1525, in na_op
#     result[mask] = op(xrav, y)
# TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and 'Timedelta'

# During handling of the above exception, another exception occurred:

# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
#   File "/usr/local/lib/python3.6/site-packages/pandas/core/ops.py", line 1559, in f
#     return self._combine_const(other, na_op, try_cast=True)
#   File "/usr/local/lib/python3.6/site-packages/pandas/core/frame.py", line 4779, in _combine_const
#     try_cast=try_cast)
#   File "/usr/local/lib/python3.6/site-packages/pandas/core/internals.py", line 3687, in eval
#     return self.apply('eval', **kwargs)
#   File "/usr/local/lib/python3.6/site-packages/pandas/core/internals.py", line 3581, in apply
#     applied = getattr(b, f)(**kwargs)
#   File "/usr/local/lib/python3.6/site-packages/pandas/core/internals.py", line 1360, in eval
#     try_cast=try_cast, mgr=mgr)
#   File "/usr/local/lib/python3.6/site-packages/pandas/core/internals.py", line 1422, in eval
#     result = handle_error()
#   File "/usr/local/lib/python3.6/site-packages/pandas/core/internals.py", line 1405, in handle_error
#     '{detail!s}'.format(other=other, detail=detail))  # noqa
# TypeError: Could not operate Timedelta('1 days 00:00:00') with block values unsupported operand type(s) for +: 'numpy.ndarray' and 'Timedelta'

Problem description

Similar to #21610, but it's easier to fix, because Timedelta is a fixed offset.

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Darwin
OS-release: 17.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: zh_CN.UTF-8
LOCALE: zh_CN.UTF-8

pandas: 0.23.3
pytest: 3.6.3
pip: 10.0.1
setuptools: 39.2.0
Cython: 0.28.4
numpy: 1.14.5
scipy: 1.1.0
pyarrow: 0.9.0.post1
xarray: None
IPython: None
sphinx: 1.6.2
patsy: None
dateutil: 2.7.2
pytz: 2018.4
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.2
openpyxl: 2.5.4
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: 3.8.0
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.