Skip to content

BUG: iterparse on read_xml overwrites nested child elements #51183

Closed
@bama-chi

Description

@bama-chi

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 as pd

XML ='''
   <values>
       <guidedSaleKey>
           <code>9023000918982</code>
           <externalReference>0102350511</externalReference>
       </guidedSaleKey>
       <store>
           <code>02300</code>
           <externalReference>1543</externalReference>
           <currency>EUR</currency>
       </store>
   </values>
'''

df = pd.read_xml(XML,iterparse={"values":["code","code"]}, names=["guided_code","store_code"])
print(df)

Issue Description

dataframe will not be able to return value of both code elements from guidedSaleKey and store
this will return this:

     guided_code     store_code
0  9023000918982  9023000918982

Expected Behavior

this should return a dataframe like this:

     guided_code     store_code
0  9023000918982  2300

Installed Versions

INSTALLED VERSIONS

commit : 87cfe4e
python : 3.10.4.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-137-generic
Version : #154-Ubuntu SMP Thu Jan 5 17:03:22 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.0
numpy : 1.23.4
pytz : 2022.5
dateutil : 2.8.2
setuptools : 58.1.0
pip : 22.0.4
Cython : None
pytest : 7.1.3
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy :
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO XMLread_xml, to_xmlNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions