Pandas version checks

  • [X] I have checked that this issue has not already been reported.

  • [X] I have confirmed this bug exists on the latest version of pandas.

  • [X] 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 : fd3f57170aa1af588ba877e8e28c158a20a4886d 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

Comment From: ParfaitG

Hi, apologies for late reply. Since iterparse iteratively parses XML documents and never holds the full tree in memory and XSLT stylesheets require reading the full tree, iterparse and stylesheets cannot be used at the same time to parse XML. However. if your use case does use both methods on same XML, please post such an interesting example.

Rather than raising exceptions at the many uses of these optional arguments of IO methods, docs should be used. But read_xml and IO tools docs mentions iterparse does not use xpath being the alternative method to traverse and parse trees. And xpath and stylesheets work together. Maybe added clarity can help.