diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 1b1a497df4ca7..ac7447420596a 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1,7 +1,6 @@ import operator import re import time -from typing import Any import warnings import cython @@ -364,7 +363,7 @@ cdef class BaseOffset: self.normalize = normalize self._cache = {} - def __eq__(self, other: Any) -> bool: + def __eq__(self, other) -> bool: if isinstance(other, str): try: # GH#23524 if to_offset fails, we are dealing with an diff --git a/pandas/io/excel/_odfreader.py b/pandas/io/excel/_odfreader.py index c105465cddd95..e0c5a2c6a7ff9 100644 --- a/pandas/io/excel/_odfreader.py +++ b/pandas/io/excel/_odfreader.py @@ -1,4 +1,4 @@ -from typing import List +from __future__ import annotations import numpy as np @@ -51,7 +51,7 @@ def empty_value(self) -> str: return "" @property - def sheet_names(self) -> List[str]: + def sheet_names(self) -> list[str]: """Return a list of sheet names present in the document""" from odf.table import Table @@ -78,7 +78,7 @@ def get_sheet_by_name(self, name: str): self.close() raise ValueError(f"sheet {name} not found") - def get_sheet_data(self, sheet, convert_float: bool) -> List[List[Scalar]]: + def get_sheet_data(self, sheet, convert_float: bool) -> list[list[Scalar]]: """ Parse an ODF Table into a list of lists """ @@ -96,12 +96,12 @@ def get_sheet_data(self, sheet, convert_float: bool) -> List[List[Scalar]]: empty_rows = 0 max_row_len = 0 - table: List[List[Scalar]] = [] + table: list[list[Scalar]] = [] for sheet_row in sheet_rows: sheet_cells = [x for x in sheet_row.childNodes if x.qname in cell_names] empty_cells = 0 - table_row: List[Scalar] = [] + table_row: list[Scalar] = [] for sheet_cell in sheet_cells: if sheet_cell.qname == table_cell_name: diff --git a/pandas/io/excel/_pyxlsb.py b/pandas/io/excel/_pyxlsb.py index 02b8090adcfdf..52a67336aaa82 100644 --- a/pandas/io/excel/_pyxlsb.py +++ b/pandas/io/excel/_pyxlsb.py @@ -1,4 +1,4 @@ -from typing import List +from __future__ import annotations from pandas._typing import ( FilePathOrBuffer, @@ -47,7 +47,7 @@ def load_workbook(self, filepath_or_buffer: FilePathOrBuffer): return open_workbook(filepath_or_buffer) @property - def sheet_names(self) -> List[str]: + def sheet_names(self) -> list[str]: return self.book.sheets def get_sheet_by_name(self, name: str): @@ -74,7 +74,7 @@ def _convert_cell(self, cell, convert_float: bool) -> Scalar: return cell.v - def get_sheet_data(self, sheet, convert_float: bool) -> List[List[Scalar]]: + def get_sheet_data(self, sheet, convert_float: bool) -> list[list[Scalar]]: data: list[list[Scalar]] = [] prevous_row_number = -1 # When sparse=True the rows can have different lengths and empty rows are diff --git a/pandas/io/excel/_util.py b/pandas/io/excel/_util.py index 6612b681a9171..7d8028de23257 100644 --- a/pandas/io/excel/_util.py +++ b/pandas/io/excel/_util.py @@ -1,7 +1,6 @@ -from typing import ( - List, - MutableMapping, -) +from __future__ import annotations + +from typing import MutableMapping from pandas.compat._optional import import_optional_dependency @@ -110,7 +109,7 @@ def _excel2num(x: str) -> int: return index - 1 -def _range2cols(areas: str) -> List[int]: +def _range2cols(areas: str) -> list[int]: """ Convert comma separated list of column names and ranges to indices. @@ -131,7 +130,7 @@ def _range2cols(areas: str) -> List[int]: >>> _range2cols('A,C,Z:AB') [0, 2, 25, 26, 27] """ - cols: List[int] = [] + cols: list[int] = [] for rng in areas.split(","): if ":" in rng: diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 616f46624bfd7..bfe431f93b725 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -1,5 +1,6 @@ +from __future__ import annotations + from datetime import datetime -from typing import List import numpy as np import pytest @@ -287,7 +288,7 @@ def test_is_string_dtype_nullable(nullable_string_dtype): assert com.is_string_dtype(pd.array(["a", "b"], dtype=nullable_string_dtype)) -integer_dtypes: List = [] +integer_dtypes: list = [] @pytest.mark.parametrize( @@ -319,7 +320,7 @@ def test_is_not_integer_dtype(dtype): assert not com.is_integer_dtype(dtype) -signed_integer_dtypes: List = [] +signed_integer_dtypes: list = [] @pytest.mark.parametrize( @@ -355,7 +356,7 @@ def test_is_not_signed_integer_dtype(dtype): assert not com.is_signed_integer_dtype(dtype) -unsigned_integer_dtypes: List = [] +unsigned_integer_dtypes: list = [] @pytest.mark.parametrize( diff --git a/pandas/tests/frame/common.py b/pandas/tests/frame/common.py index 65f228f2be411..a1603ea3dc17a 100644 --- a/pandas/tests/frame/common.py +++ b/pandas/tests/frame/common.py @@ -1,4 +1,4 @@ -from typing import List +from __future__ import annotations from pandas import ( DataFrame, @@ -39,7 +39,7 @@ def _check_mixed_int(df, dtype=None): assert df.dtypes["D"] == dtypes["D"] -def zip_frames(frames: List[DataFrame], axis: int = 1) -> DataFrame: +def zip_frames(frames: list[DataFrame], axis: int = 1) -> DataFrame: """ take a list of frames, zip them together under the assumption that these all have the first frames' index/columns. diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index 0ea3abcaefcf2..cef756b709f70 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -1,6 +1,7 @@ +from __future__ import annotations + from datetime import datetime import gc -from typing import Type import numpy as np import pytest @@ -36,7 +37,7 @@ class Base: Base class for index sub-class tests. """ - _index_cls: Type[Index] + _index_cls: type[Index] @pytest.fixture def simple_index(self): diff --git a/pandas/tests/indexing/test_coercion.py b/pandas/tests/indexing/test_coercion.py index 26f2ba577d184..145f9741d03d1 100644 --- a/pandas/tests/indexing/test_coercion.py +++ b/pandas/tests/indexing/test_coercion.py @@ -1,9 +1,7 @@ +from __future__ import annotations + from datetime import timedelta import itertools -from typing import ( - Dict, - List, -) import numpy as np import pytest @@ -1024,7 +1022,7 @@ class TestReplaceSeriesCoercion(CoercionBase): klasses = ["series"] method = "replace" - rep: Dict[str, List] = {} + rep: dict[str, list] = {} rep["object"] = ["a", "b"] rep["int64"] = [4, 5] rep["float64"] = [1.1, 2.2] diff --git a/pandas/tests/io/xml/test_to_xml.py b/pandas/tests/io/xml/test_to_xml.py index c588c3c3ca0bd..1e2973075f98e 100644 --- a/pandas/tests/io/xml/test_to_xml.py +++ b/pandas/tests/io/xml/test_to_xml.py @@ -1,9 +1,10 @@ +from __future__ import annotations + from io import ( BytesIO, StringIO, ) import os -from typing import Union import numpy as np import pytest @@ -963,7 +964,7 @@ def test_stylesheet_file_like(datapath, mode): def test_stylesheet_io(datapath, mode): xsl_path = datapath("io", "data", "xml", "row_field_output.xsl") - xsl_obj: Union[BytesIO, StringIO] + xsl_obj: BytesIO | StringIO with open(xsl_path, mode) as f: if mode == "rb": diff --git a/pandas/tests/io/xml/test_xml.py b/pandas/tests/io/xml/test_xml.py index 95751b6090a06..823d155360908 100644 --- a/pandas/tests/io/xml/test_xml.py +++ b/pandas/tests/io/xml/test_xml.py @@ -1,9 +1,10 @@ +from __future__ import annotations + from io import ( BytesIO, StringIO, ) import os -from typing import Union from urllib.error import HTTPError import numpy as np @@ -792,7 +793,7 @@ def test_stylesheet_io(datapath, mode): kml = datapath("io", "data", "xml", "cta_rail_lines.kml") xsl = datapath("io", "data", "xml", "flatten_doc.xsl") - xsl_obj: Union[BytesIO, StringIO] + xsl_obj: BytesIO | StringIO with open(xsl, mode) as f: if mode == "rb": @@ -942,7 +943,7 @@ def test_stylesheet_file_close(datapath, mode): kml = datapath("io", "data", "xml", "cta_rail_lines.kml") xsl = datapath("io", "data", "xml", "flatten_doc.xsl") - xsl_obj: Union[BytesIO, StringIO] + xsl_obj: BytesIO | StringIO with open(xsl, mode) as f: if mode == "rb": diff --git a/pandas/tests/tseries/offsets/test_offsets.py b/pandas/tests/tseries/offsets/test_offsets.py index 8872b76cd9bce..08dbc1345b9d4 100644 --- a/pandas/tests/tseries/offsets/test_offsets.py +++ b/pandas/tests/tseries/offsets/test_offsets.py @@ -1,6 +1,8 @@ """ Tests of pandas.tseries.offsets """ +from __future__ import annotations + from datetime import ( datetime, timedelta, diff --git a/scripts/validate_rst_title_capitalization.py b/scripts/validate_rst_title_capitalization.py index aa17afc4c33ea..9aca47dbddbf2 100755 --- a/scripts/validate_rst_title_capitalization.py +++ b/scripts/validate_rst_title_capitalization.py @@ -11,14 +11,12 @@ From the command-line: python scripts/validate_rst_title_capitalization.py """ +from __future__ import annotations + import argparse import re import sys -from typing import ( - Iterable, - List, - Tuple, -) +from typing import Iterable CAPITALIZATION_EXCEPTIONS = { "pandas", @@ -201,7 +199,7 @@ def correct_title_capitalization(title: str) -> str: return correct_title -def find_titles(rst_file: str) -> Iterable[Tuple[str, int]]: +def find_titles(rst_file: str) -> Iterable[tuple[str, int]]: """ Algorithm to identify particular text that should be considered headings in an RST file. @@ -237,7 +235,7 @@ def find_titles(rst_file: str) -> Iterable[Tuple[str, int]]: previous_line = line -def main(source_paths: List[str]) -> int: +def main(source_paths: list[str]) -> int: """ The main method to print all headings with incorrect capitalization.