8000 Misc Type Annotation fixes (#26372) · pandas-dev/pandas@0e9589d · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e9589d

Browse files
gwromeWillAyd
authored andcommitted
Misc Type Annotation fixes (#26372)
* Add type annotations to io.pytables * Start correcting mypy errors in core.window * Complete misc type fixes * Fix import sort on test_groupby.py * Update after code reviews * Whatsnew, second rev indexing, window and pytables * Annotate Set in core.window * Define attributes as List[str]
1 parent ebe6b91 commit 0e9589d

File tree

12 files changed

+34
-57
lines changed

12 files changed

+34
-57
lines changed

doc/source/whatsnew/v0.25.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ Other API Changes
249 8000 249
- Comparing :class:`Timestamp` with unsupported objects now returns :py:obj:`NotImplemented` instead of raising ``TypeError``. This implies that unsupported rich comparisons are delegated to the other object, and are now consistent with Python 3 behavior for ``datetime`` objects (:issue:`24011`)
250250
- Bug in :meth:`DatetimeIndex.snap` which didn't preserving the ``name`` of the input :class:`Index` (:issue:`25575`)
251251
- The ``arg`` argument in :meth:`pandas.core.groupby.DataFrameGroupBy.agg` has been renamed to ``func`` (:issue:`26089`)
252+
- The ``arg`` argument in :meth:`pandas.core.window._Window.aggregate` has been renamed to ``func`` (:issue:`26372`)
252253

253254
.. _whatsnew_0250.deprecations:
254255

mypy.ini

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,4 @@ ignore_errors=True
1515
ignore_errors=True
1616

1717
[mypy-pandas.core.indexes.timedeltas]
18-
ignore_errors=True
19-
20-
[mypy-pandas.core.indexing]
21-
ignore_errors=True
22-
23-
[mypy-pandas.core.internals.blocks]
24-
ignore_errors=True
25-
26-
[mypy-pandas.core.panel]
27-
ignore_errors=True
28-
29-
[mypy-pandas.core.reshape.merge]
30-
ignore_errors=True
31-
32-
[mypy-pandas.core.reshape.reshape]
33-
ignore_errors=True
34-
35-
[mypy-pandas.core.series]
36-
ignore_errors=True
37-
38-
[mypy-pandas.core.util.hashing]
39-
ignore_errors=True
40-
41-
[mypy-pandas.core.window]
42-
ignore_errors=True
43-
44-
[mypy-pandas.io.pytables]
45-
ignore_errors=True
46-
47-
[mypy-pandas.util._doctools]
48-
ignore_errors=True
49-
50-
[mypy-pandas.util.testing]
51-
ignore_errors=True
18+
ignore_errors=True

pandas/core/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1569,5 +1569,5 @@ def duplicated(self, keep='first'):
15691569
# ----------------------------------------------------------------------
15701570
# abstracts
15711571

1572-
def _update_inplace(self, result, **kwargs):
1572+
def _update_inplace(self, result, verify_is_copy=True, **kwargs):
15731573
raise AbstractMethodError(self)

pandas/core/generic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import operator
77
import pickle
88
from textwrap import dedent
9-
from typing import FrozenSet, List, Set
9+
from typing import Callable, FrozenSet, List, Set
1010
import warnings
1111
import weakref
1212

@@ -3680,7 +3680,7 @@ class animal locomotion
36803680
result._set_is_copy(self, copy=not result._is_view)
36813681
return result
36823682

3683-
_xs = xs
3683+
_xs = xs # type: Callable
36843684

36853685
def select(self, crit, axis=0):
36863686
"""

pandas/core/indexing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ class IndexingError(Exception):
8888

8989

9090
class _NDFrameIndexer(_NDFrameIndexerBase):
91-
_valid_types = None
92-
_exception = KeyError
91+
_valid_types = None # type: str
92+
_exception = Exception
9393
axis = None
9494

9595
def __call__(self, axis=None):

pandas/core/internals/blocks.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
import numpy as np
99

10-
from pandas._libs import internals as libinternals, lib, tslib, tslibs
10+
from pandas._libs import lib, tslib, tslibs
11+
import pandas._libs.internals as libinternals
1112
from pandas._libs.tslibs import Timedelta, conversion, is_null_datetimelike
1213
from pandas.util._validators import validate_bool_kwarg
1314

@@ -2050,12 +2051,15 @@ def get_values(self, dtype=None):
20502051
class DatetimeBlock(DatetimeLikeBlockMixin, Block):
20512052
__slots__ = ()
20522053
is_datetime = True
2053-
_can_hold_na = True
20542054

20552055
def __init__(self, values, placement, ndim=None):
20562056
values = self._maybe_coerce_values(values)
20572057
super().__init__(values, placement=placement, ndim=ndim)
20582058

2059+
@property
2060+
def _can_hold_na(self):
2061+
return True
2062+
20592063
def _maybe_coerce_values(self, values):
20602064
"""Input validation for values passed to __init__. Ensure that
20612065
we have datetime64ns, coercing if necessary.

pandas/core/reshape/merge.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
import numpy as np
1010

11-
from pandas._libs import hashtable as libhashtable, join as libjoin, lib
11+
from pandas._libs import hashtable as libhashtable, lib
12+
import pandas._libs.join as libjoin
1213
from pandas.errors import MergeError
1314
from pandas.util._decorators import Appender, Substitution
1415

pandas/core/reshape/reshape.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import numpy as np
55

6-
from pandas._libs import algos as _algos, reshape as _reshape
6+
import pandas._libs.algos as _algos
7+
import pandas._libs.reshape as _reshape
78
from pandas._libs.sparse import IntIndex
89

910
from pandas.core.dtypes.cast import maybe_promote

pandas/core/util/hashing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
import numpy as np
77

8-
from pandas._libs import hashing, tslibs
8+
import pandas._libs.hashing as hashing
9+
import pandas._libs.tslibs as tslibs
910

1011
from pandas.core.dtypes.cast import infer_dtype_from_scalar
1112
from pandas.core.dtypes.common import (

pandas/core/window.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from collections import defaultdict
66
from datetime import timedelta
77
from textwrap import dedent
8+
from typing import Set
89
import warnings
910

1011
import numpy as np
@@ -42,7 +43,7 @@
4243
class _Window(PandasObject, SelectionMixin):
4344
_attributes = ['window', 'min_periods', 'center', 'win_type',
4445
'axis', 'on', 'closed']
45-
exclusions = set()
46+
exclusions = set() # type: Set[str]
4647

4748
def __init__(self, obj, window=None, min_periods=None,
4849
center=False, win_type=None, axis=0, on=None, closed=None,
@@ -305,10 +306,10 @@ def _center_window(self, result, window):
305306
result = np.copy(result[tuple(lead_indexer)])
306307
return result
307308

308-
def aggregate(self, arg, *args, **kwargs):
309-
result, how = self._aggregate(arg, *args, **kwargs)
309+
def aggregate(self, func, *args, **kwargs):
310+
result, how = self._aggregate(func, *args, **kwargs)
310311
if result is None:
311-
return self.apply(arg, raw=False, args=args, kwargs=kwargs)
312+
return self.apply(func, raw=False, args=args, kwargs=kwargs)
312313
return result
313314

314315
agg = aggregate
@@ -788,7 +789,7 @@ def __init__(self, obj, *args, **kwargs):
788789
corr = GroupByMixin._dispatch('corr', other=None, pairwise=None)
789790
cov = GroupByMixin._dispatch('cov', other=None, pairwise=None)
790791

791-
def _apply(self, func, name, window=None, center=None,
792+
def _apply(self, func, name=None, window=None, center=None,
792793
check_minp=None, **kwargs):
793794
"""
794795
Dispatch to apply; we are stripping all of the _apply kwargs and

0 commit comments

Comments
 (0)
0