Skip to content

CLN: add typing for dtype arg in directories core/indexes and core/strings (GH38808) #38890

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 3 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from pandas._libs import index as libindex
from pandas._libs.lib import no_default
from pandas._typing import ArrayLike, Label
from pandas._typing import ArrayLike, Dtype, Label
from pandas.util._decorators import Appender, doc

from pandas.core.dtypes.common import (
Expand Down Expand Up @@ -180,7 +180,13 @@ def _engine_type(self):
# Constructors

def __new__(
cls, data=None, categories=None, ordered=None, dtype=None, copy=False, name=None
cls,
data=None,
categories=None,
ordered=None,
dtype: Optional[Dtype] = None,
copy=False,
name=None,
):

name = maybe_extract_name(name, data, cls)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
to_offset,
)
from pandas._libs.tslibs.offsets import prefix_mapping
from pandas._typing import DtypeObj
from pandas._typing import Dtype, DtypeObj
from pandas.errors import InvalidIndexError
from pandas.util._decorators import cache_readonly, doc

Expand Down Expand Up @@ -289,7 +289,7 @@ def __new__(
ambiguous="raise",
dayfirst=False,
yearfirst=False,
dtype=None,
dtype: Optional[Dtype] = None,
copy=False,
name=None,
):
Expand Down
20 changes: 15 additions & 5 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pandas._libs import lib
from pandas._libs.interval import Interval, IntervalMixin, IntervalTree
from pandas._libs.tslibs import BaseOffset, Timedelta, Timestamp, to_offset
from pandas._typing import DtypeObj, Label
from pandas._typing import Dtype, DtypeObj, Label
from pandas.errors import InvalidIndexError
from pandas.util._decorators import Appender, cache_readonly
from pandas.util._exceptions import rewrite_exception
Expand Down Expand Up @@ -192,7 +192,7 @@ def __new__(
cls,
data,
closed=None,
dtype=None,
dtype: Optional[Dtype] = None,
copy: bool = False,
name=None,
verify_integrity: bool = True,
Expand Down Expand Up @@ -249,7 +249,12 @@ def _simple_new(cls, array: IntervalArray, name: Label = None):
}
)
def from_breaks(
cls, breaks, closed: str = "right", name=None, copy: bool = False, dtype=None
cls,
breaks,
closed: str = "right",
name=None,
copy: bool = False,
dtype: Optional[Dtype] = None,
):
with rewrite_exception("IntervalArray", cls.__name__):
array = IntervalArray.from_breaks(
Expand Down Expand Up @@ -281,7 +286,7 @@ def from_arrays(
closed: str = "right",
name=None,
copy: bool = False,
dtype=None,
dtype: Optional[Dtype] = None,
):
with rewrite_exception("IntervalArray", cls.__name__):
array = IntervalArray.from_arrays(
Expand All @@ -307,7 +312,12 @@ def from_arrays(
}
)
def from_tuples(
cls, data, closed: str = "right", name=None, copy: bool = False, dtype=None
cls,
data,
closed: str = "right",
name=None,
copy: bool = False,
dtype: Optional[Dtype] = None,
):
with rewrite_exception("IntervalArray", cls.__name__):
arr = IntervalArray.from_tuples(data, closed=closed, copy=copy, dtype=dtype)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, Optional
import warnings

import numpy as np
Expand Down Expand Up @@ -45,7 +45,7 @@ class NumericIndex(Index):
_is_numeric_dtype = True
_can_hold_strings = False

def __new__(cls, data=None, dtype=None, copy=False, name=None):
def __new__(cls, data=None, dtype: Optional[Dtype] = None, copy=False, name=None):
name = maybe_extract_name(name, data, cls)

subarr = cls._ensure_array(data, dtype, copy)
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from datetime import datetime, timedelta
from typing import Any
from typing import Any, Optional
import warnings

import numpy as np

from pandas._libs import index as libindex, lib
from pandas._libs.tslibs import BaseOffset, Period, Resolution, Tick
from pandas._libs.tslibs.parsing import DateParseError, parse_time_string
from pandas._typing import DtypeObj
from pandas._typing import Dtype, DtypeObj
from pandas.errors import InvalidIndexError
from pandas.util._decorators import cache_readonly, doc

Expand Down Expand Up @@ -190,7 +190,7 @@ def __new__(
data=None,
ordinal=None,
freq=None,
dtype=None,
dtype: Optional[Dtype] = None,
copy=False,
name=None,
**fields,
Expand Down
16 changes: 12 additions & 4 deletions pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from pandas._libs import index as libindex
from pandas._libs.lib import no_default
from pandas._typing import Label
from pandas._typing import Dtype, Label
from pandas.compat.numpy import function as nv
from pandas.util._decorators import cache_readonly, doc

Expand Down Expand Up @@ -83,7 +83,13 @@ class RangeIndex(Int64Index):
# Constructors

def __new__(
cls, start=None, stop=None, step=None, dtype=None, copy=False, name=None
cls,
start=None,
stop=None,
step=None,
dtype: Optional[Dtype] = None,
copy=False,
name=None,
):

cls._validate_dtype(dtype)
Expand Down Expand Up @@ -113,7 +119,9 @@ def __new__(
return cls._simple_new(rng, name=name)

@classmethod
def from_range(cls, data: range, name=None, dtype=None) -> "RangeIndex":
def from_range(
cls, data: range, name=None, dtype: Optional[Dtype] = None
) -> "RangeIndex":
"""
Create RangeIndex from a range object.

Expand Down Expand Up @@ -405,7 +413,7 @@ def _shallow_copy(self, values=None, name: Label = no_default):
return result

@doc(Int64Index.copy)
def copy(self, name=None, deep=False, dtype=None, names=None):
def copy(self, name=None, deep=False, dtype: Optional[Dtype] = None, names=None):
name = self._validate_names(name=name, names=names, deep=deep)[0]
new_index = self._shallow_copy(name=name)

Expand Down
6 changes: 3 additions & 3 deletions pandas/core/strings/object_array.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
import textwrap
from typing import Pattern, Set, Union, cast
from typing import Optional, Pattern, Set, Union, cast
import unicodedata
import warnings

Expand All @@ -9,7 +9,7 @@
import pandas._libs.lib as lib
import pandas._libs.missing as libmissing
import pandas._libs.ops as libops
from pandas._typing import Scalar
from pandas._typing import NpDtype, Scalar

from pandas.core.dtypes.common import is_re, is_scalar
from pandas.core.dtypes.missing import isna
Expand All @@ -28,7 +28,7 @@ def __len__(self):
# For typing, _str_map relies on the object being sized.
raise NotImplementedError

def _str_map(self, f, na_value=None, dtype=None):
def _str_map(self, f, na_value=None, dtype: Optional[NpDtype] = None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is Dtype

"""
Map a callable over valid element of the array.

Expand Down