Skip to content

Commit 05780f8

Browse files
WillAydjreback
authored andcommitted
Unpin pycodestyle (#25789)
1 parent a70eb0f commit 05780f8

29 files changed

+98
-71
lines changed

environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies:
1919
- hypothesis>=3.82
2020
- isort
2121
- moto
22-
- pycodestyle=2.4
22+
- pycodestyle
2323
- pytest>=4.0.2
2424
- pytest-mock
2525
- sphinx

pandas/_libs/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# flake8: noqa
33

44
from .tslibs import (
5-
iNaT, NaT, Timestamp, Timedelta, OutOfBoundsDatetime, Period)
5+
iNaT, NaT, NaTType, Timestamp, Timedelta, OutOfBoundsDatetime, Period)

pandas/_libs/tslibs/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# flake8: noqa
33

44
from .conversion import normalize_date, localize_pydatetime, tz_convert_single
5-
from .nattype import NaT, iNaT, is_null_datetimelike
5+
from .nattype import NaT, NaTType, iNaT, is_null_datetimelike
66
from .np_datetime import OutOfBoundsDatetime
77
from .period import Period, IncompatibleFrequency
88
from .timestamps import Timestamp

pandas/_libs/tslibs/nattype.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ class NaTType(_NaT):
353353
354354
.. versionadded:: 0.23.0
355355
""")
356-
day_name = _make_nan_func('day_name', # noqa:E128
356+
day_name = _make_nan_func('day_name', # noqa:E128
357357
"""
358358
Return the day name of the Timestamp with specified locale.
359359

pandas/core/arrays/array_.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
from typing import Optional, Sequence, Union
2+
3+
import numpy as np
4+
15
from pandas._libs import lib, tslibs
26

37
from pandas.core.dtypes.common import (
48
is_datetime64_ns_dtype, is_extension_array_dtype, is_timedelta64_ns_dtype)
5-
from pandas.core.dtypes.dtypes import registry
9+
from pandas.core.dtypes.dtypes import ExtensionDtype, registry
610

711
from pandas import compat
812

pandas/core/arrays/base.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
without warning.
77
"""
88
import operator
9+
from typing import Any, Callable, Optional, Sequence, Tuple, Union
910

1011
import numpy as np
1112

@@ -15,6 +16,7 @@
1516
from pandas.util._decorators import Appender, Substitution
1617

1718
from pandas.core.dtypes.common import is_list_like
19+
from pandas.core.dtypes.dtypes import ExtensionDtype
1820
from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries
1921
from pandas.core.dtypes.missing import isna
2022

@@ -365,7 +367,7 @@ def isna(self):
365367
raise AbstractMethodError(self)
366368

367369
def _values_for_argsort(self):
368-
# type: () -> ndarray
370+
# type: () -> np.ndarray
369371
"""
370372
Return values for sorting.
371373
@@ -597,7 +599,7 @@ def searchsorted(self, value, side="left", sorter=None):
597599
return arr.searchsorted(value, side=side, sorter=sorter)
598600

599601
def _values_for_factorize(self):
600-
# type: () -> Tuple[ndarray, Any]
602+
# type: () -> Tuple[np.ndarray, Any]
601603
"""
602604
Return an array and missing value suitable for factorization.
603605
@@ -622,7 +624,7 @@ def _values_for_factorize(self):
622624
return self.astype(object), np.nan
623625

624626
def factorize(self, na_sentinel=-1):
625-
# type: (int) -> Tuple[ndarray, ExtensionArray]
627+
# type: (int) -> Tuple[np.ndarray, ExtensionArray]
626628
"""
627629
Encode the extension array as an enumerated type.
628630

pandas/core/arrays/datetimelike.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# -*- coding: utf-8 -*-
22
from datetime import datetime, timedelta
33
import operator
4+
from typing import Any, Sequence, Tuple, Union
45
import warnings
56

67
import numpy as np
78

8-
from pandas._libs import NaT, algos, iNaT, lib
9+
from pandas._libs import NaT, NaTType, Timestamp, algos, iNaT, lib
910
from pandas._libs.tslibs.period import (
1011
DIFFERENT_FREQ, IncompatibleFrequency, Period)
1112
from pandas._libs.tslibs.timedeltas import Timedelta, delta_to_nanoseconds
@@ -350,7 +351,7 @@ def __iter__(self):
350351

351352
@property
352353
def asi8(self):
353-
# type: () -> ndarray
354+
# type: () -> np.ndarray
354355
"""
355356
Integer representation of the values.
356357
@@ -461,10 +462,10 @@ def __getitem__(self, key):
461462
def __setitem__(
462463
self,
463464
key, # type: Union[int, Sequence[int], Sequence[bool], slice]
464-
value, # type: Union[NaTType, Scalar, Sequence[Scalar]]
465+
value, # type: Union[NaTType, Any, Sequence[Any]]
465466
):
466467
# type: (...) -> None
467-
# I'm fudging the types a bit here. The "Scalar" above really depends
468+
# I'm fudging the types a bit here. "Any" above really depends
468469
# on type(self). For PeriodArray, it's Period (or stuff coercible
469470
# to a period in from_sequence). For DatetimeArray, it's Timestamp...
470471
# I don't know if mypy can do that, possibly with Generics.

pandas/core/arrays/datetimes.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
from datetime import datetime, time, timedelta
33
import textwrap
4+
from typing import Union
45
import warnings
56

67
import numpy as np

pandas/core/arrays/integer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ def value_counts(self, dropna=True):
510510
return Series(array, index=index)
511511

512512
def _values_for_argsort(self):
513-
# type: () -> ndarray
513+
# type: () -> np.ndarray
514514
"""Return values for sorting.
515515
516516
Returns

pandas/core/arrays/period.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# -*- coding: utf-8 -*-
22
from datetime import timedelta
33
import operator
4+
from typing import Any, Callable, Optional, Sequence, Union
45

56
import numpy as np
67

78
from pandas._libs.tslibs import (
8-
NaT, frequencies as libfrequencies, iNaT, period as libperiod)
9+
NaT, NaTType, frequencies as libfrequencies, iNaT, period as libperiod)
910
from pandas._libs.tslibs.fields import isleapyear_arr
1011
from pandas._libs.tslibs.period import (
1112
DIFFERENT_FREQ, IncompatibleFrequency, Period, get_period_field_arr,
@@ -23,7 +24,7 @@
2324
from pandas.core.dtypes.missing import isna, notna
2425

2526
import pandas.core.algorithms as algos
26-
from pandas.core.arrays import datetimelike as dtl
27+
from pandas.core.arrays import ExtensionArray, datetimelike as dtl
2728
import pandas.core.common as com
2829

2930
from pandas.tseries import frequencies
@@ -536,11 +537,14 @@ def _sub_period(self, other):
536537
@Appender(dtl.DatetimeLikeArrayMixin._addsub_int_array.__doc__)
537538
def _addsub_int_array(
538539
self,
539-
other, # type: Union[Index, ExtensionArray, np.ndarray[int]]
540-
op # type: Callable[Any, Any]
540+
other, # type: Union[ExtensionArray, np.ndarray[int]]
541+
op # type: Callable[Any, Any]
541542
):
542543
# type: (...) -> PeriodArray
543544

545+
# TODO: ABCIndexClass is a valid type for other but had to be excluded
546+
# due to length of Py2 compatability comment; add back in once migrated
547+
# to Py3 syntax
544548
assert op in [operator.add, operator.sub]
545549
if op is operator.sub:
546550
other = -other

pandas/core/arrays/sparse.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
import numbers
77
import operator
88
import re
9+
from typing import Any, Callable, Union
910
import warnings
1011

1112
import numpy as np
1213

1314
from pandas._libs import index as libindex, lib
1415
import pandas._libs.sparse as splib
15-
from pandas._libs.sparse import BlockIndex, IntIndex
16+
from pandas._libs.sparse import BlockIndex, IntIndex, SparseIndex
1617
from pandas._libs.tslibs import NaT
1718
import pandas.compat as compat
1819
from pandas.compat.numpy import function as nv
@@ -372,7 +373,7 @@ def _subtype_with_str(self):
372373

373374

374375
def _get_fill(arr):
375-
# type: (SparseArray) -> ndarray
376+
# type: (SparseArray) -> np.ndarray
376377
"""
377378
Create a 0-dim ndarray containing the fill value
378379

pandas/core/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
from pandas.core import algorithms, common as com
2626
from pandas.core.accessor import DirNamesMixin
27+
from pandas.core.arrays import ExtensionArray
2728
import pandas.core.nanops as nanops
2829

2930
_shared_docs = dict()

pandas/core/common.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from datetime import datetime, timedelta
1010
from functools import partial
1111
import inspect
12+
from typing import Any
1213

1314
import numpy as np
1415

pandas/core/dtypes/base.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Extend pandas with custom array types"""
2+
from typing import List, Optional, Type
3+
24
import numpy as np
35

46
from pandas.errors import AbstractMethodError
@@ -211,7 +213,7 @@ def __str__(self):
211213

212214
@property
213215
def type(self):
214-
# type: () -> type
216+
# type: () -> Type
215217
"""
216218
The scalar type for the array, e.g. ``int``
217219

pandas/core/dtypes/dtypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ def construct_from_string(cls, string):
937937

938938
if (string.lower() == 'interval' or
939939
cls._match.search(string) is not None):
940-
return cls(string)
940+
return cls(string)
941941

942942
msg = ('Incorrectly formatted string passed to constructor. '
943943
'Valid formats include Interval or Interval[dtype] '

pandas/core/frame.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import sys
2020
import warnings
2121
from textwrap import dedent
22+
from typing import List, Union
2223

2324
import numpy as np
2425
import numpy.ma as ma

pandas/core/groupby/groupby.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class providing the base-class of operations.
1212
import datetime
1313
from functools import partial, wraps
1414
import types
15+
from typing import Optional, Type
1516
import warnings
1617

1718
import numpy as np
@@ -1040,7 +1041,7 @@ def _bool_agg(self, val_test, skipna):
10401041
"""
10411042

10421043
def objs_to_bool(vals):
1043-
# type: (np.ndarray) -> (np.ndarray, typing.Type)
1044+
# type: (np.ndarray) -> (np.ndarray, Type)
10441045
if is_object_dtype(vals):
10451046
vals = np.array([bool(x) for x in vals])
10461047
else:
@@ -1049,7 +1050,7 @@ def objs_to_bool(vals):
10491050
return vals.view(np.uint8), np.bool
10501051

10511052
def result_to_bool(result, inference):
1052-
# type: (np.ndarray, typing.Type) -> np.ndarray
1053+
# type: (np.ndarray, Type) -> np.ndarray
10531054
return result.astype(inference, copy=False)
10541055

10551056
return self._get_cythonized_result('group_any_all', self.grouper,
@@ -1738,7 +1739,7 @@ def quantile(self, q=0.5, interpolation='linear'):
17381739
"""
17391740

17401741
def pre_processor(vals):
1741-
# type: (np.ndarray) -> (np.ndarray, Optional[typing.Type])
1742+
# type: (np.ndarray) -> (np.ndarray, Optional[Type])
17421743
if is_object_dtype(vals):
17431744
raise TypeError("'quantile' cannot be performed against "
17441745
"'object' dtypes!")
@@ -1753,7 +1754,7 @@ def pre_processor(vals):
17531754
return vals, inference
17541755

17551756
def post_processor(vals, inference):
1756-
# type: (np.ndarray, Optional[typing.Type]) -> np.ndarray
1757+
# type: (np.ndarray, Optional[Type]) -> np.ndarray
17571758
if inference:
17581759
# Check for edge case
17591760
if not (is_integer_dtype(inference) and
@@ -2016,7 +2017,7 @@ def _get_cythonized_result(self, how, grouper, aggregate=False,
20162017
Function to be applied to result of Cython function. Should accept
20172018
an array of values as the first argument and type inferences as its
20182019
second argument, i.e. the signature should be
2019-
(ndarray, typing.Type).
2020+
(ndarray, Type).
20202021
**kwargs : dict
20212022
Extra arguments to be passed back to Cython funcs
20222023

pandas/core/indexes/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import datetime, timedelta
22
import operator
33
from textwrap import dedent
4+
from typing import Union
45
import warnings
56

67
import numpy as np

pandas/core/internals/blocks.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import functools
44
import inspect
55
import re
6+
from typing import Any, List
67
import warnings
78

89
import numpy as np
@@ -1826,8 +1827,11 @@ def interpolate(self, method='pad', axis=0, inplace=False, limit=None,
18261827
limit=limit),
18271828
placement=self.mgr_locs)
18281829

1829-
def shift(self, periods, axis=0, fill_value=None):
1830-
# type: (int, Optional[BlockPlacement], Any) -> List[ExtensionBlock]
1830+
def shift(self,
1831+
periods, # type: int
1832+
axis=0, # type: libinternals.BlockPlacement
1833+
fill_value=None): # type: Any
1834+
# type: (...) -> List[ExtensionBlock]
18311835
"""
18321836
Shift the block by `periods`.
18331837

pandas/core/internals/managers.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import itertools
55
import operator
66
import re
7+
from typing import List, Optional, Union
78

89
import numpy as np
910

@@ -18,6 +19,7 @@
1819
_NS_DTYPE, is_datetimelike_v_numeric, is_extension_array_dtype,
1920
is_extension_type, is_list_like, is_numeric_v_string_like, is_scalar)
2021
import pandas.core.dtypes.concat as _concat
22+
from pandas.core.dtypes.dtypes import ExtensionDtype
2123
from pandas.core.dtypes.generic import ABCExtensionArray, ABCSeries
2224
from pandas.core.dtypes.missing import isna
2325

pandas/io/formats/format.py

-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,6 @@ def _chk_truncate(self):
440440
max_rows = self.max_rows
441441

442442
if max_cols == 0 or max_rows == 0: # assume we are in the terminal
443-
# (why else = 0)
444443
(w, h) = get_terminal_size()
445444
self.w = w
446445
self.h = h

pandas/tests/frame/test_alter_axes.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ def test_set_index_pass_arrays_duplicate(self, frame_of_index_cols, drop,
201201
# need to adapt first drop for case that both keys are 'A' --
202202
# cannot drop the same column twice;
203203
# use "is" because == would give ambiguous Boolean error for containers
204-
first_drop = False if (keys[0] is 'A' and keys[1] is 'A') else drop
204+
first_drop = False if (
205+
keys[0] is 'A' and keys[1] is 'A') else drop # noqa: F632
205206

206207
# to test against already-tested behaviour, we add sequentially,
207208
# hence second append always True; must wrap keys in list, otherwise
@@ -1272,7 +1273,7 @@ def test_rename_axis_style_raises(self):
12721273
df.rename(id, mapper=id)
12731274

12741275
def test_reindex_api_equivalence(self):
1275-
# equivalence of the labels/axis and index/columns API's
1276+
# equivalence of the labels/axis and index/columns API's
12761277
df = DataFrame([[1, 2, 3], [3, 4, 5], [5, 6, 7]],
12771278
index=['a', 'b', 'c'],
12781279
columns=['d', 'e', 'f'])

pandas/tests/groupby/test_apply.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def test_apply_issues():
12-
# GH 5788
12+
# GH 5788
1313

1414
s = """2011.05.16,00:00,1.40893
1515
2011.05.16,01:00,1.40760

0 commit comments

Comments
 (0)