|
5 | 5 | from __future__ import annotations
|
6 | 6 |
|
7 | 7 | import io
|
8 |
| -from typing import Iterable |
| 8 | +from typing import Sequence |
9 | 9 |
|
10 | 10 | from pandas._typing import (
|
11 | 11 | CompressionOptions,
|
@@ -102,10 +102,10 @@ def __init__(
|
102 | 102 | self,
|
103 | 103 | path_or_buffer: FilePath | ReadBuffer[bytes] | ReadBuffer[str],
|
104 | 104 | xpath: str,
|
105 |
| - namespaces: dict | list[dict] | None, |
| 105 | + namespaces: dict | None, |
106 | 106 | elems_only: bool,
|
107 | 107 | attrs_only: bool,
|
108 |
| - names: Iterable[str] | None, |
| 108 | + names: Sequence[str] | None, |
109 | 109 | encoding: str | None,
|
110 | 110 | stylesheet: FilePath | ReadBuffer[bytes] | ReadBuffer[str] | None,
|
111 | 111 | compression: CompressionOptions,
|
@@ -543,6 +543,11 @@ def _parse_doc(self, raw_doc) -> bytes:
|
543 | 543 | curr_parser = XMLParser(encoding=self.encoding)
|
544 | 544 |
|
545 | 545 | if isinstance(xml_data, io.StringIO):
|
| 546 | + if self.encoding is None: |
| 547 | + raise TypeError( |
| 548 | + "Can not pass encoding None when input is StringIO." |
| 549 | + ) |
| 550 | + |
546 | 551 | doc = fromstring(
|
547 | 552 | xml_data.getvalue().encode(self.encoding), parser=curr_parser
|
548 | 553 | )
|
@@ -659,10 +664,10 @@ class that build Data Frame and infers specific dtypes.
|
659 | 664 | def _parse(
|
660 | 665 | path_or_buffer: FilePath | ReadBuffer[bytes] | ReadBuffer[str],
|
661 | 666 | xpath: str,
|
662 |
| - namespaces: dict | list[dict] | None, |
| 667 | + namespaces: dict | None, |
663 | 668 | elems_only: bool,
|
664 | 669 | attrs_only: bool,
|
665 |
| - names: Iterable[str] | None, |
| 670 | + names: Sequence[str] | None, |
666 | 671 | encoding: str | None,
|
667 | 672 | parser: XMLParsers,
|
668 | 673 | stylesheet: FilePath | ReadBuffer[bytes] | ReadBuffer[str] | None,
|
@@ -734,10 +739,11 @@ def _parse(
|
734 | 739 | def read_xml(
|
735 | 740 | path_or_buffer: FilePath | ReadBuffer[bytes] | ReadBuffer[str],
|
736 | 741 | xpath: str = "./*",
|
737 |
| - namespaces: dict | list[dict] | None = None, |
| 742 | + namespaces: dict | None = None, |
738 | 743 | elems_only: bool = False,
|
739 | 744 | attrs_only: bool = False,
|
740 |
| - names: Iterable[str] | None = None, |
| 745 | + names: Sequence[str] | None = None, |
| 746 | + # encoding can not be None for lxml and StringIO input |
741 | 747 | encoding: str | None = "utf-8",
|
742 | 748 | parser: XMLParsers = "lxml",
|
743 | 749 | stylesheet: FilePath | ReadBuffer[bytes] | ReadBuffer[str] | None = None,
|
|
0 commit comments