From 749994e17ee6f8d0983555fabad179038c7b43e7 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Thu, 28 Aug 2025 19:51:04 +0100 Subject: [PATCH] TYP: improve type annotations in pandas.io.xml - Updated get_data_from_filepath signature and removed unnecessary type ignores. - Added type annotations for preprocess_data and _data_to_frame. --- pandas/io/xml.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pandas/io/xml.py b/pandas/io/xml.py index 0fcf27af42fde..e14f401d41f2a 100644 --- a/pandas/io/xml.py +++ b/pandas/io/xml.py @@ -666,7 +666,7 @@ def _transform_doc(self) -> etree._XSLTResultTree: def get_data_from_filepath( - filepath_or_buffer: FilePath | bytes | ReadBuffer[bytes] | ReadBuffer[str], + filepath_or_buffer: FilePath | ReadBuffer[bytes] | ReadBuffer[str], encoding: str | None, compression: CompressionOptions, storage_options: StorageOptions, @@ -678,9 +678,9 @@ def get_data_from_filepath( 1. filepath (string-like) 2. file-like object (e.g. open file object, StringIO) """ - filepath_or_buffer = stringify_path(filepath_or_buffer) # type: ignore[arg-type] - with get_handle( # pyright: ignore[reportCallIssue] - filepath_or_buffer, # pyright: ignore[reportArgumentType] + filepath_or_buffer = stringify_path(filepath_or_buffer) + with get_handle( + filepath_or_buffer, "r", encoding=encoding, compression=compression, @@ -693,7 +693,9 @@ def get_data_from_filepath( ) -def preprocess_data(data) -> io.StringIO | io.BytesIO: +def preprocess_data( + data: str | bytes | io.StringIO | io.BytesIO, +) -> io.StringIO | io.BytesIO: """ Convert extracted raw data. @@ -711,7 +713,7 @@ def preprocess_data(data) -> io.StringIO | io.BytesIO: return data -def _data_to_frame(data, **kwargs) -> DataFrame: +def _data_to_frame(data: list[dict[str, str | None]], **kwargs) -> DataFrame: """ Convert parsed data to Data Frame.