Skip to content

BUG: pandas read_xml with iterparse and stylesheets silently ignores stylesheets #58857

@cloudcode-hungary

Description

@cloudcode-hungary

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

data = read_xml(
    ...,
    parser='lxml',
    stylesheet=stylesheet,
    iterparse=iterparse,
)

The stylesheet is ignored.

Issue Description

        if self.iterparse is None:
            self.xml_doc = self._parse_doc(self.path_or_buffer)

            if self.stylesheet:
                self.xsl_doc = self._parse_doc(self.stylesheet)
                self.xml_doc = self._transform_doc()

            elems = self._validate_path()

this should be continued with:

elif self.stylesheet:
    raise SomeExceptionExplaining("iterparse and stylesheet can not be used together")

or better is it possible to implement it?

Silent failure is definietly misleading and it took quite some time to get it, as "everything" was correct, checking with other tools the stylesheet was transforming correctly, yet the read xml yielded different results.

Expected Behavior

Raise exception or implement stylesheet on iterparse

Installed Versions

INSTALLED VERSIONS

commit : fd3f571
python : 3.10.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.10.192-183.736.amzn2.x86_64
Version : #1 SMP Wed Sep 6 21:15:41 UTC 2023
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.0
numpy : 1.26.3
pytz : 2020.4
dateutil : 2.8.2
setuptools : 58.1.0
pip : 23.3.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.3
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.28.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
zstandard : None
tzdata : 2023.4
qtpy : None
pyqt5 : 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