pd.Timestamp.utctimetuple() raises TypeError on Python 3.8 · Issue #32174 · pandas-dev/pandas (original) (raw)
Hi there,
it seems that something changed in python 3.8 that makes pandas.Timestamp.utctimetuple()
raise a TypeError
instead of producing a time.struct_time
.
Code Sample
In [1]: date = pd.to_datetime("2000-01-01", utc=True)
In [2]: date.utctimetuple()
TypeError Traceback (most recent call last) in ----> 1 date.utctimetuple()
pandas/_libs/tslibs/timestamps.pyx in pandas._libs.tslibs.timestamps.Timestamp.new()
TypeError: an integer is required
Expected Output
With earlier Python versions the output is:
In [3]: date.utctimetuple()
Out[3]: time.struct_time(tm_year=2000, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=5, tm_yday=1, tm_isdst=0)
An intermediate workaround can be to convert to datetime.datetime
(python 3.8):
In [4]: date.to_pydatetime().utctimetuple()
Out[4]: time.struct_time(tm_year=2000, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=5, tm_yday=1, tm_isdst=0)
Output of pd.show_versions()
commit : None
python : 3.8.1.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-1066-oem
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C
LOCALE : en_GB.UTF-8
pandas : 1.0.1
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 45.1.0.post20200119
Cython : None
pytest : 5.3.5
hypothesis : 5.5.1
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : 7.12.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.1.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.3.5
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : 0.15.0
xlrd : None
xlwt : None
xlsxwriter : None
numba : None