Skip to content

TYP: clean for PY3.8 (final) #42422

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 5 commits into from
Jul 14, 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: 3 additions & 0 deletions pandas/_libs/internals.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import (
Iterator,
Sequence,
final,
overload,
)

Expand Down Expand Up @@ -50,10 +51,12 @@ class SharedBlock:

class NumpyBlock(SharedBlock):
values: np.ndarray
@final
def getitem_block_index(self: T, slicer: slice) -> T: ...

class NDArrayBackedBlock(SharedBlock):
values: NDArrayBackedExtensionArray
@final
def getitem_block_index(self: T, slicer: slice) -> T: ...

class Block(SharedBlock): ...
Expand Down
2 changes: 0 additions & 2 deletions pandas/_libs/internals.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ cdef class NumpyBlock(SharedBlock):
# set placement and ndim
self.values = values

# @final # not useful in cython, but we _would_ annotate with @final
cpdef NumpyBlock getitem_block_index(self, slice slicer):
"""
Perform __getitem__-like specialized to slicing along index.
Expand All @@ -540,7 +539,6 @@ cdef class NDArrayBackedBlock(SharedBlock):
# set placement and ndim
self.values = values

# @final # not useful in cython, but we _would_ annotate with @final
cpdef NDArrayBackedBlock getitem_block_index(self, slice slicer):
"""
Perform __getitem__-like specialized to slicing along index.
Expand Down
7 changes: 1 addition & 6 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@
# and use a string literal forward reference to it in subsequent types
# https://mypy.readthedocs.io/en/latest/common_issues.html#import-cycles
if TYPE_CHECKING:
from typing import (
TypedDict,
final,
)
from typing import TypedDict

import numpy.typing as npt

Expand Down Expand Up @@ -76,8 +73,6 @@
from pandas.tseries.offsets import DateOffset
else:
npt: Any = None
# typing.final does not exist until py38
final = lambda x: x
# typing.TypedDict does not exist until py38
TypedDict = dict

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Literal,
TypeVar,
cast,
final,
)

import numpy as np
Expand All @@ -24,7 +25,6 @@
FrameOrSeries,
IndexLabel,
Shape,
final,
npt,
)
from pandas.compat import PYPY
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Mapping,
Sequence,
cast,
final,
overload,
)
import warnings
Expand Down Expand Up @@ -54,7 +55,6 @@
TimedeltaConvertibleTypes,
TimestampConvertibleTypes,
ValueKeyFunc,
final,
npt,
)
from pandas.compat._optional import import_optional_dependency
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class providing the base-class of operations.
TypeVar,
Union,
cast,
final,
)
import warnings

Expand All @@ -49,7 +50,6 @@ class providing the base-class of operations.
RandomState,
Scalar,
T,
final,
)
from pandas.compat.numpy import function as nv
from pandas.errors import AbstractMethodError
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/groupby/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
"""
from __future__ import annotations

from typing import Hashable
from typing import (
Hashable,
final,
)
import warnings

import numpy as np

from pandas._typing import (
ArrayLike,
FrameOrSeries,
final,
)
from pandas.errors import InvalidIndexError
from pandas.util._decorators import cache_readonly
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Hashable,
Iterator,
Sequence,
final,
overload,
)

Expand All @@ -31,7 +32,6 @@
F,
FrameOrSeries,
Shape,
final,
npt,
)
from pandas.errors import AbstractMethodError
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Sequence,
TypeVar,
cast,
final,
overload,
)
import warnings
Expand Down Expand Up @@ -44,7 +45,6 @@
F,
Shape,
T,
final,
npt,
)
from pandas.compat.numpy import function as nv
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Sequence,
TypeVar,
cast,
final,
)
import warnings

Expand All @@ -28,7 +29,6 @@
Tick,
parsing,
)
from pandas._typing import final
from pandas.compat.numpy import function as nv
from pandas.util._decorators import (
Appender,
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/internals/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
"""
from __future__ import annotations

from typing import TypeVar
from typing import (
TypeVar,
final,
)

from pandas._typing import (
DtypeObj,
Shape,
final,
)
from pandas.errors import AbstractMethodError

Expand Down
28 changes: 13 additions & 15 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Iterable,
Sequence,
cast,
final,
)
import warnings

Expand All @@ -28,7 +29,6 @@
DtypeObj,
F,
Shape,
final,
)
from pandas.util._decorators import cache_readonly
from pandas.util._validators import validate_bool_kwarg
Expand Down Expand Up @@ -312,17 +312,6 @@ def getitem_block(self, slicer) -> Block:

return type(self)(new_values, new_mgr_locs, self.ndim)

def getitem_block_index(self, slicer: slice) -> Block:
"""
Perform __getitem__-like specialized to slicing along index.

Assumes self.ndim == 2
"""
# error: Invalid index type "Tuple[ellipsis, slice]" for
# "Union[ndarray, ExtensionArray]"; expected type "Union[int, slice, ndarray]"
new_values = self.values[..., slicer] # type: ignore[index]
return type(self)(new_values, self._mgr_locs, ndim=self.ndim)

@final
def getitem_block_columns(self, slicer, new_mgr_locs: BlockPlacement) -> Block:
"""
Expand Down Expand Up @@ -1557,6 +1546,18 @@ def _slice(self, slicer):

return self.values[slicer]

@final
def getitem_block_index(self, slicer: slice) -> ExtensionBlock:
"""
Perform __getitem__-like specialized to slicing along index.

Assumes self.ndim == 2
"""
# error: Invalid index type "Tuple[ellipsis, slice]" for
# "Union[ndarray, ExtensionArray]"; expected type "Union[int, slice, ndarray]"
new_values = self.values[..., slicer] # type: ignore[index]
return type(self)(new_values, self._mgr_locs, ndim=self.ndim)

def fillna(
self, value, limit=None, inplace: bool = False, downcast=None
) -> list[Block]:
Expand Down Expand Up @@ -1661,8 +1662,6 @@ def _unstack(self, unstacker, fill_value, new_placement):
class NumpyBlock(libinternals.NumpyBlock, Block):
values: np.ndarray

getitem_block_index = libinternals.NumpyBlock.getitem_block_index


class NumericBlock(NumpyBlock):
__slots__ = ()
Expand All @@ -1675,7 +1674,6 @@ class NDArrayBackedExtensionBlock(libinternals.NDArrayBackedBlock, EABackedBlock
"""

values: NDArrayBackedExtensionArray
getitem_block_index = libinternals.NDArrayBackedBlock.getitem_block_index

@property
def is_view(self) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Callable,
Hashable,
Literal,
final,
no_type_check,
)

Expand All @@ -27,7 +28,6 @@
T,
TimedeltaConvertibleTypes,
TimestampConvertibleTypes,
final,
npt,
)
from pandas.compat.numpy import function as nv
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/parsers/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Iterable,
Sequence,
cast,
final,
)
import warnings

Expand All @@ -26,7 +27,6 @@
ArrayLike,
DtypeArg,
FilePathOrBuffer,
final,
)
from pandas.errors import (
ParserError,
Expand Down