Skip to content

WIP for MyPy CI Integration #25622

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

Closed
wants to merge 13 commits into from
Prev Previous commit
Next Next commit
First cleanup pass for pandas.core.arrays
  • Loading branch information
WillAyd committed Mar 10, 2019
commit 9b5daaa41dadc8861b65a53321b928c498d4b9af
7 changes: 6 additions & 1 deletion pandas/core/arrays/array_.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from typing import Optional, Sequence, Union

import numpy as np

from pandas._libs import lib, tslibs

from pandas.core.arrays.base import ExtensionArray
from pandas.core.dtypes.common import (
is_datetime64_ns_dtype, is_extension_array_dtype, is_timedelta64_ns_dtype)
from pandas.core.dtypes.dtypes import registry
from pandas.core.dtypes.dtypes import ExtensionDtype, registry

from pandas import compat

Expand Down
8 changes: 5 additions & 3 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
without warning.
"""
import operator
from typing import Any, Callable, Optional, Sequence, Tuple, Union

import numpy as np

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

from pandas.core.dtypes.common import is_list_like
from pandas.core.dtypes.dtypes import ExtensionDtype
from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries
from pandas.core.dtypes.missing import isna

Expand Down Expand Up @@ -365,7 +367,7 @@ def isna(self):
raise AbstractMethodError(self)

def _values_for_argsort(self):
# type: () -> ndarray
# type: () -> np.ndarray
"""
Return values for sorting.

Expand Down Expand Up @@ -597,7 +599,7 @@ def searchsorted(self, value, side="left", sorter=None):
return arr.searchsorted(value, side=side, sorter=sorter)

def _values_for_factorize(self):
# type: () -> Tuple[ndarray, Any]
# type: () -> Tuple[np.ndarray, Any]
"""
Return an array and missing value suitable for factorization.

Expand All @@ -622,7 +624,7 @@ def _values_for_factorize(self):
return self.astype(object), np.nan

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

Expand Down
6 changes: 4 additions & 2 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
from datetime import datetime, timedelta
import operator
import warnings
from typing import Union, Sequence, Tuple

import numpy as np

from pandas._libs import NaT, algos, iNaT, lib
from pandas._libs.tslibs.nattype import NaTType
from pandas._libs.tslibs.period import (
DIFFERENT_FREQ, IncompatibleFrequency, Period)
from pandas._libs.tslibs.timedeltas import Timedelta, delta_to_nanoseconds
from pandas._libs.tslibs.timestamps import (
RoundTo, maybe_integer_op_deprecated, round_nsint64)
RoundTo, maybe_integer_op_deprecated, round_nsint64, Timestamp)
import pandas.compat as compat
from pandas.compat.numpy import function as nv
from pandas.errors import (
Expand Down Expand Up @@ -350,7 +352,7 @@ def __iter__(self):

@property
def asi8(self):
# type: () -> ndarray
# type: () -> np.ndarray
"""
Integer representation of the values.

Expand Down
1 change: 1 addition & 0 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime, time, timedelta
import textwrap
import warnings
from typing import Union

import numpy as np
from pytz import utc
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def value_counts(self, dropna=True):
return Series(array, index=index)

def _values_for_argsort(self):
# type: () -> ndarray
# type: () -> np.ndarray
"""Return values for sorting.

Returns
Expand Down
6 changes: 5 additions & 1 deletion pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# -*- coding: utf-8 -*-
from datetime import timedelta
import operator
from typing import Any, Callable, List, Optional, Sequence, Union

import numpy as np

from pandas._libs.tslibs import (
NaT, frequencies as libfrequencies, iNaT, period as libperiod)
from pandas._libs.tslibs.nattype import NaTType
from pandas._libs.tslibs.fields import isleapyear_arr
from pandas._libs.tslibs.period import (
DIFFERENT_FREQ, IncompatibleFrequency, Period, get_period_field_arr,
period_asfreq_arr)
from pandas._libs.tslibs.timedeltas import Timedelta, delta_to_nanoseconds
import pandas.compat as compat
from pandas.core.arrays.base import ExtensionArray
from pandas.core.indexes.base import Index
from pandas.util._decorators import Appender, cache_readonly

from pandas.core.dtypes.common import (
Expand Down Expand Up @@ -132,7 +136,7 @@ class PeriodArray(dtl.DatetimeLikeArrayMixin, dtl.DatelikeOps):
_scalar_type = Period

# Names others delegate to us
_other_ops = []
_other_ops = [] # type: List[str]
_bool_ops = ['is_leap_year']
_object_ops = ['start_time', 'end_time', 'freq']
_field_ops = ['year', 'month', 'day', 'hour', 'minute', 'second',
Expand Down
7 changes: 4 additions & 3 deletions pandas/core/arrays/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import operator
import re
import warnings
from typing import Any, Callable, Type, Union

import numpy as np

from pandas._libs import index as libindex, lib
import pandas._libs.sparse as splib
from pandas._libs.sparse import BlockIndex, IntIndex
from pandas._libs.sparse import BlockIndex, IntIndex, SparseIndex
from pandas._libs.tslibs import NaT
import pandas.compat as compat
from pandas.compat.numpy import function as nv
Expand Down Expand Up @@ -79,7 +80,7 @@ class SparseDtype(ExtensionDtype):
_metadata = ('_dtype', '_fill_value', '_is_na_fill_value')

def __init__(self, dtype=np.float64, fill_value=None):
# type: (Union[str, np.dtype, 'ExtensionDtype', type], Any) -> None
# type: (Union[str, np.dtype, 'ExtensionDtype', Type], Any) -> None
from pandas.core.dtypes.missing import na_value_for_dtype
from pandas.core.dtypes.common import (
pandas_dtype, is_string_dtype, is_scalar
Expand Down Expand Up @@ -372,7 +373,7 @@ def _subtype_with_str(self):


def _get_fill(arr):
# type: (SparseArray) -> ndarray
# type: (SparseArray) -> np.ndarray
"""
Create a 0-dim ndarray containing the fill value

Expand Down
5 changes: 3 additions & 2 deletions pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import timedelta
import textwrap
import warnings
from typing import List

import numpy as np

Expand Down Expand Up @@ -134,8 +135,8 @@ class TimedeltaArray(dtl.DatetimeLikeArrayMixin, dtl.TimelikeOps):
_scalar_type = Timedelta
__array_priority__ = 1000
# define my properties & methods for delegation
_other_ops = []
_bool_ops = []
_other_ops = [] # type: List[str]
_bool_ops = [] # type: List[str]
_object_ops = ['freq']
_field_ops = ['days', 'seconds', 'microseconds', 'nanoseconds']
_datetimelike_ops = _field_ops + _object_ops + _bool_ops
Expand Down