Skip to content

Commit ab8f1c6

Browse files
committed
Fix typing issues
1 parent baa3ab2 commit ab8f1c6

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

pandas/io/xml.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import annotations
66

77
import io
8-
from typing import Iterable
8+
from typing import Sequence
99

1010
from pandas._typing import (
1111
CompressionOptions,
@@ -102,10 +102,10 @@ def __init__(
102102
self,
103103
path_or_buffer: FilePath | ReadBuffer[bytes] | ReadBuffer[str],
104104
xpath: str,
105-
namespaces: dict | list[dict] | None,
105+
namespaces: dict | None,
106106
elems_only: bool,
107107
attrs_only: bool,
108-
names: Iterable[str] | None,
108+
names: Sequence[str] | None,
109109
encoding: str | None,
110110
stylesheet: FilePath | ReadBuffer[bytes] | ReadBuffer[str] | None,
111111
compression: CompressionOptions,
@@ -543,6 +543,11 @@ def _parse_doc(self, raw_doc) -> bytes:
543543
curr_parser = XMLParser(encoding=self.encoding)
544544

545545
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+
546551
doc = fromstring(
547552
xml_data.getvalue().encode(self.encoding), parser=curr_parser
548553
)
@@ -659,10 +664,10 @@ class that build Data Frame and infers specific dtypes.
659664
def _parse(
660665
path_or_buffer: FilePath | ReadBuffer[bytes] | ReadBuffer[str],
661666
xpath: str,
662-
namespaces: dict | list[dict] | None,
667+
namespaces: dict | None,
663668
elems_only: bool,
664669
attrs_only: bool,
665-
names: Iterable[str] | None,
670+
names: Sequence[str] | None,
666671
encoding: str | None,
667672
parser: XMLParsers,
668673
stylesheet: FilePath | ReadBuffer[bytes] | ReadBuffer[str] | None,
@@ -734,10 +739,11 @@ def _parse(
734739
def read_xml(
735740
path_or_buffer: FilePath | ReadBuffer[bytes] | ReadBuffer[str],
736741
xpath: str = "./*",
737-
namespaces: dict | list[dict] | None = None,
742+
namespaces: dict | None = None,
738743
elems_only: bool = False,
739744
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
741747
encoding: str | None = "utf-8",
742748
parser: XMLParsers = "lxml",
743749
stylesheet: FilePath | ReadBuffer[bytes] | ReadBuffer[str] | None = None,

0 commit comments

Comments
 (0)