Skip to content

Commit 949592a

Browse files
TYP: clean for PY3.8 (final) (pandas-dev#42422)
1 parent b4aa48f commit 949592a

File tree

14 files changed

+33
-35
lines changed

14 files changed

+33
-35
lines changed

pandas/_libs/internals.pyi

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import (
22
Iterator,
33
Sequence,
4+
final,
45
overload,
56
)
67

@@ -50,10 +51,12 @@ class SharedBlock:
5051

5152
class NumpyBlock(SharedBlock):
5253
values: np.ndarray
54+
@final
5355
def getitem_block_index(self: T, slicer: slice) -> T: ...
5456

5557
class NDArrayBackedBlock(SharedBlock):
5658
values: NDArrayBackedExtensionArray
59+
@final
5760
def getitem_block_index(self: T, slicer: slice) -> T: ...
5861

5962
class Block(SharedBlock): ...

pandas/_libs/internals.pyx

-2
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ cdef class NumpyBlock(SharedBlock):
517517
# set placement and ndim
518518
self.values = values
519519

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

543-
# @final # not useful in cython, but we _would_ annotate with @final
544542
cpdef NDArrayBackedBlock getitem_block_index(self, slice slicer):
545543
"""
546544
Perform __getitem__-like specialized to slicing along index.

pandas/_typing.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@
3737
# and use a string literal forward reference to it in subsequent types
3838
# https://mypy.readthedocs.io/en/latest/common_issues.html#import-cycles
3939
if TYPE_CHECKING:
40-
from typing import (
41-
TypedDict,
42-
final,
43-
)
40+
from typing import TypedDict
4441

4542
import numpy.typing as npt
4643

@@ -76,8 +73,6 @@
7673
from pandas.tseries.offsets import DateOffset
7774
else:
7875
npt: Any = None
79-
# typing.final does not exist until py38
80-
final = lambda x: x
8176
# typing.TypedDict does not exist until py38
8277
TypedDict = dict
8378

pandas/core/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Literal,
1414
TypeVar,
1515
cast,
16+
final,
1617
)
1718

1819
import numpy as np
@@ -24,7 +25,6 @@
2425
FrameOrSeries,
2526
IndexLabel,
2627
Shape,
27-
final,
2828
npt,
2929
)
3030
from pandas.compat import PYPY

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Mapping,
1919
Sequence,
2020
cast,
21+
final,
2122
overload,
2223
)
2324
import warnings
@@ -54,7 +55,6 @@
5455
TimedeltaConvertibleTypes,
5556
TimestampConvertibleTypes,
5657
ValueKeyFunc,
57-
final,
5858
npt,
5959
)
6060
from pandas.compat._optional import import_optional_dependency

pandas/core/groupby/groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class providing the base-class of operations.
2929
TypeVar,
3030
Union,
3131
cast,
32+
final,
3233
)
3334
import warnings
3435

@@ -49,7 +50,6 @@ class providing the base-class of operations.
4950
RandomState,
5051
Scalar,
5152
T,
52-
final,
5353
)
5454
from pandas.compat.numpy import function as nv
5555
from pandas.errors import AbstractMethodError

pandas/core/groupby/grouper.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
"""
55
from __future__ import annotations
66

7-
from typing import Hashable
7+
from typing import (
8+
Hashable,
9+
final,
10+
)
811
import warnings
912

1013
import numpy as np
1114

1215
from pandas._typing import (
1316
ArrayLike,
1417
FrameOrSeries,
15-
final,
1618
)
1719
from pandas.errors import InvalidIndexError
1820
from pandas.util._decorators import cache_readonly

pandas/core/groupby/ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Hashable,
1515
Iterator,
1616
Sequence,
17+
final,
1718
overload,
1819
)
1920

@@ -31,7 +32,6 @@
3132
F,
3233
FrameOrSeries,
3334
Shape,
34-
final,
3535
npt,
3636
)
3737
from pandas.errors import AbstractMethodError

pandas/core/indexes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Sequence,
1414
TypeVar,
1515
cast,
16+
final,
1617
overload,
1718
)
1819
import warnings
@@ -44,7 +45,6 @@
4445
F,
4546
Shape,
4647
T,
47-
final,
4848
npt,
4949
)
5050
from pandas.compat.numpy import function as nv

pandas/core/indexes/datetimelike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Sequence,
1212
TypeVar,
1313
cast,
14+
final,
1415
)
1516
import warnings
1617

@@ -28,7 +29,6 @@
2829
Tick,
2930
parsing,
3031
)
31-
from pandas._typing import final
3232
from pandas.compat.numpy import function as nv
3333
from pandas.util._decorators import (
3434
Appender,

pandas/core/internals/base.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
"""
55
from __future__ import annotations
66

7-
from typing import TypeVar
7+
from typing import (
8+
TypeVar,
9+
final,
10+
)
811

912
from pandas._typing import (
1013
DtypeObj,
1114
Shape,
12-
final,
1315
)
1416
from pandas.errors import AbstractMethodError
1517

pandas/core/internals/blocks.py

+13-15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Iterable,
1010
Sequence,
1111
cast,
12+
final,
1213
)
1314
import warnings
1415

@@ -28,7 +29,6 @@
2829
DtypeObj,
2930
F,
3031
Shape,
31-
final,
3232
)
3333
from pandas.util._decorators import cache_readonly
3434
from pandas.util._validators import validate_bool_kwarg
@@ -312,17 +312,6 @@ def getitem_block(self, slicer) -> Block:
312312

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

315-
def getitem_block_index(self, slicer: slice) -> Block:
316-
"""
317-
Perform __getitem__-like specialized to slicing along index.
318-
319-
Assumes self.ndim == 2
320-
"""
321-
# error: Invalid index type "Tuple[ellipsis, slice]" for
322-
# "Union[ndarray, ExtensionArray]"; expected type "Union[int, slice, ndarray]"
323-
new_values = self.values[..., slicer] # type: ignore[index]
324-
return type(self)(new_values, self._mgr_locs, ndim=self.ndim)
325-
326315
@final
327316
def getitem_block_columns(self, slicer, new_mgr_locs: BlockPlacement) -> Block:
328317
"""
@@ -1557,6 +1546,18 @@ def _slice(self, slicer):
15571546

15581547
return self.values[slicer]
15591548

1549+
@final
1550+
def getitem_block_index(self, slicer: slice) -> ExtensionBlock:
1551+
"""
1552+
Perform __getitem__-like specialized to slicing along index.
1553+
1554+
Assumes self.ndim == 2
1555+
"""
1556+
# error: Invalid index type "Tuple[ellipsis, slice]" for
1557+
# "Union[ndarray, ExtensionArray]"; expected type "Union[int, slice, ndarray]"
1558+
new_values = self.values[..., slicer] # type: ignore[index]
1559+
return type(self)(new_values, self._mgr_locs, ndim=self.ndim)
1560+
15601561
def fillna(
15611562
self, value, limit=None, inplace: bool = False, downcast=None
15621563
) -> list[Block]:
@@ -1661,8 +1662,6 @@ def _unstack(self, unstacker, fill_value, new_placement):
16611662
class NumpyBlock(libinternals.NumpyBlock, Block):
16621663
values: np.ndarray
16631664

1664-
getitem_block_index = libinternals.NumpyBlock.getitem_block_index
1665-
16661665

16671666
class NumericBlock(NumpyBlock):
16681667
__slots__ = ()
@@ -1675,7 +1674,6 @@ class NDArrayBackedExtensionBlock(libinternals.NDArrayBackedBlock, EABackedBlock
16751674
"""
16761675

16771676
values: NDArrayBackedExtensionArray
1678-
getitem_block_index = libinternals.NDArrayBackedBlock.getitem_block_index
16791677

16801678
@property
16811679
def is_view(self) -> bool:

pandas/core/resample.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Callable,
88
Hashable,
99
Literal,
10+
final,
1011
no_type_check,
1112
)
1213

@@ -27,7 +28,6 @@
2728
T,
2829
TimedeltaConvertibleTypes,
2930
TimestampConvertibleTypes,
30-
final,
3131
npt,
3232
)
3333
from pandas.compat.numpy import function as nv

pandas/io/parsers/base_parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Iterable,
1313
Sequence,
1414
cast,
15+
final,
1516
)
1617
import warnings
1718

@@ -26,7 +27,6 @@
2627
ArrayLike,
2728
DtypeArg,
2829
FilePathOrBuffer,
29-
final,
3030
)
3131
from pandas.errors import (
3232
ParserError,

0 commit comments

Comments
 (0)