Code Sample, a copy-pastable example if possible
>>> import pandas as pd
>>> import datetime as dt
>>> pd.Series([dt.datetime.max.replace(tzinfo=dt.timezone.utc)]).tz_convert('Europe/Berlin')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'datetime.datetime' object is not callable
>>> pd.Series([dt.datetime.max.replace(tzinfo=dt.timezone.utc)]).tz_convert('Europe/Berlin')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/var/local/conda/envs/pandas-debug/lib/python3.7/site-packages/pandas/core/generic.py", line 9703, in tz_convert
ax = _tz_convert(ax, tz)
File "/var/local/conda/envs/pandas-debug/lib/python3.7/site-packages/pandas/core/generic.py", line 9686, in _tz_convert
"%s is not a valid DatetimeIndex or " "PeriodIndex" % ax_name
TypeError: index is not a valid DatetimeIndex or PeriodIndex
>>> pd.Series([dt.datetime.max.replace(tzinfo=dt.timezone.utc)]).dt.tz_convert('Europe/Berlin')
Traceback (most recent call last):
File "/var/local/conda/envs/pandas-debug/lib/python3.7/site-packages/pandas/core/arrays/datetimes.py", line 1979, in objects_to_datetime64ns
values, tz_parsed = conversion.datetime_to_datetime64(data)
File "pandas/_libs/tslibs/conversion.pyx", line 189, in pandas._libs.tslibs.conversion.datetime_to_datetime64
File "pandas/_libs/tslibs/conversion.pyx", line 399, in pandas._libs.tslibs.conversion.convert_datetime_to_tsobject
File "pandas/_libs/tslibs/np_datetime.pyx", line 118, in pandas._libs.tslibs.np_datetime.check_dts_bounds
pandas._libs.tslibs.np_datetime.OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 9999-12-31 23:59:59
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/var/local/conda/envs/pandas-debug/lib/python3.7/site-packages/pandas/core/accessor.py", line 93, in f
return self._delegate_method(name, *args, **kwargs)
File "/var/local/conda/envs/pandas-debug/lib/python3.7/site-packages/pandas/core/indexes/accessors.py", line 106, in _delegate_method
values = self._get_values()
File "/var/local/conda/envs/pandas-debug/lib/python3.7/site-packages/pandas/core/indexes/accessors.py", line 55, in _get_values
return DatetimeIndex(data, copy=False, name=self.name)
File "/var/local/conda/envs/pandas-debug/lib/python3.7/site-packages/pandas/core/indexes/datetimes.py", line 334, in __new__
int_as_wall_time=True,
File "/var/local/conda/envs/pandas-debug/lib/python3.7/site-packages/pandas/core/arrays/datetimes.py", line 446, in _from_sequence
int_as_wall_time=int_as_wall_time,
File "/var/local/conda/envs/pandas-debug/lib/python3.7/site-packages/pandas/core/arrays/datetimes.py", line 1866, in sequence_to_dt64ns
data, dayfirst=dayfirst, yearfirst=yearfirst
File "/var/local/conda/envs/pandas-debug/lib/python3.7/site-packages/pandas/core/arrays/datetimes.py", line 1984, in objects_to_datetime64ns
raise e
File "/var/local/conda/envs/pandas-debug/lib/python3.7/site-packages/pandas/core/arrays/datetimes.py", line 1975, in objects_to_datetime64ns
require_iso8601=require_iso8601,
File "pandas/_libs/tslib.pyx", line 465, in pandas._libs.tslib.array_to_datetime
File "pandas/_libs/tslib.pyx", line 543, in pandas._libs.tslib.array_to_datetime
ValueError: Tz-aware datetime.datetime cannot be converted to datetime64 unless utc=True
Problem description
The error message of the outer exception above is misleading. The inner exception has the right error message, but in many cases (e.g. log files) only the outer exception's message is displayed.
If I understand things correctly, the underlying issue is discussed in #12677. In contrast to that ticket I'm fine with getting the exception but would like a clearer message.
Expected Output
The inner exception message should be kept instead of being replaced with a misleading new message.
Output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Linux
OS-release : 5.0.0-29-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 0.25.1
numpy : 1.16.5
pytz : 2019.2
dateutil : 2.8.0
pip : 19.2.3
setuptools : 41.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
Comment From: mroeschke
This case doesn't look possible since the original series in now an object type so closing