BUG: Converting string of type lxml.etree._ElementUnicodeResult to a datetime using pandas.to_datetime results in a TypeError. #60933
Labels
Bug
datetime.date
stdlib datetime.date support
Needs Discussion
Requires discussion from core team before further action
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
Issue Description
Hello,
When trying to convert a string that comes from an XML file parsing with
pandas.to_datetime
, I struggled with an unexpectedTypeError
.I managed to write a reproducible example that both works on the latest 2.2.3 version and
3.0.0dev
with Python 3.12.8.It looks like when I'm trying to convert datetimes in a Series initialized from a list of
lxml.etree._ElementUnicodeResult
with the argumentformat
, an error is raised.Also, using
Series.astype(str)
does not work (values are stilllxml.etre._ElementUnicodeResult
).Expected Behavior
No
TypeError
.Installed Versions
3.0.0dev
pandas : 3.0.0.dev0+1943.g19ea997815
numpy : 2.3.0.dev0+git20250211.bbfb823
dateutil : 2.9.0.post0
pip : None
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : 5.3.1
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pytz : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.1
qtpy : None
pyqt5 : None
2.2.3
pandas : 2.2.3
numpy : 2.2.2
pytz : 2025.1
dateutil : 2.9.0.post0
pip : None
Cython : None
sphinx : 8.1.3
IPython : 8.32.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.13.3
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.5
lxml.etree : 5.3.1
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : 8.3.4
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.15.1
sqlalchemy : None
tables : None
tabulate : None
xarray : 2025.1.2
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.1
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: