Skip to content

TYP: use from __future__ import annotations more - batch 6 #41900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import operator
import re
import time
from typing import Any
import warnings

import cython
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions pandas/io/excel/_odfreader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from __future__ import annotations

import numpy as np

Expand Down Expand Up @@ -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

Expand All @@ -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
"""
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions pandas/io/excel/_pyxlsb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from __future__ import annotations

from pandas._typing import (
FilePathOrBuffer,
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down
11 changes: 5 additions & 6 deletions pandas/io/excel/_util.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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.

Expand All @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions pandas/tests/dtypes/test_common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from datetime import datetime
from typing import List

import numpy as np
import pytest
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from __future__ import annotations

from pandas import (
DataFrame,
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/indexes/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from datetime import datetime
import gc
from typing import Type

import numpy as np
import pytest
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 3 additions & 5 deletions pandas/tests/indexing/test_coercion.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/io/xml/test_to_xml.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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":
Expand Down
7 changes: 4 additions & 3 deletions pandas/tests/io/xml/test_xml.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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":
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/tseries/offsets/test_offsets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Tests of pandas.tseries.offsets
"""
from __future__ import annotations

from datetime import (
datetime,
timedelta,
Expand Down
12 changes: 5 additions & 7 deletions scripts/validate_rst_title_capitalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
From the command-line:
python scripts/validate_rst_title_capitalization.py <rst file>
"""
from __future__ import annotations

import argparse
import re
import sys
from typing import (
Iterable,
List,
Tuple,
)
from typing import Iterable

CAPITALIZATION_EXCEPTIONS = {
"pandas",
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down