Skip to content

Commit ade2296

Browse files
jbrockmendelSeeminSyed
authored andcommitted
CLN: remove is_period_arraylike, is_datetime_arraylike (pandas-dev#32406)
1 parent 5eaac26 commit ade2296

File tree

5 files changed

+9
-101
lines changed

5 files changed

+9
-101
lines changed

pandas/core/dtypes/common.py

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

88
import numpy as np
99

10-
from pandas._libs import algos, lib
10+
from pandas._libs import algos
1111
from pandas._libs.tslibs import conversion
1212
from pandas._typing import ArrayLike, DtypeObj
1313

@@ -19,14 +19,7 @@
1919
PeriodDtype,
2020
registry,
2121
)
22-
from pandas.core.dtypes.generic import (
23-
ABCCategorical,
24-
ABCDatetimeIndex,
25-
ABCIndexClass,
26-
ABCPeriodArray,
27-
ABCPeriodIndex,
28-
ABCSeries,
29-
)
22+
from pandas.core.dtypes.generic import ABCCategorical, ABCIndexClass
3023
from pandas.core.dtypes.inference import ( # noqa:F401
3124
is_array_like,
3225
is_bool,
@@ -606,71 +599,6 @@ def is_excluded_dtype(dtype) -> bool:
606599
return _is_dtype(arr_or_dtype, condition)
607600

608601

609-
def is_period_arraylike(arr) -> bool:
610-
"""
611-
Check whether an array-like is a periodical array-like or PeriodIndex.
612-
613-
Parameters
614-
----------
615-
arr : array-like
616-
The array-like to check.
617-
618-
Returns
619-
-------
620-
boolean
621-
Whether or not the array-like is a periodical array-like or
622-
PeriodIndex instance.
623-
624-
Examples
625-
--------
626-
>>> is_period_arraylike([1, 2, 3])
627-
False
628-
>>> is_period_arraylike(pd.Index([1, 2, 3]))
629-
False
630-
>>> is_period_arraylike(pd.PeriodIndex(["2017-01-01"], freq="D"))
631-
True
632-
"""
633-
if isinstance(arr, (ABCPeriodIndex, ABCPeriodArray)):
634-
return True
635-
elif isinstance(arr, (np.ndarray, ABCSeries)):
636-
return is_period_dtype(arr.dtype)
637-
return getattr(arr, "inferred_type", None) == "period"
638-
639-
640-
def is_datetime_arraylike(arr) -> bool:
641-
"""
642-
Check whether an array-like is a datetime array-like or DatetimeIndex.
643-
644-
Parameters
645-
----------
646-
arr : array-like
647-
The array-like to check.
648-
649-
Returns
650-
-------
651-
boolean
652-
Whether or not the array-like is a datetime array-like or
653-
DatetimeIndex.
654-
655-
Examples
656-
--------
657-
>>> is_datetime_arraylike([1, 2, 3])
658-
False
659-
>>> is_datetime_arraylike(pd.Index([1, 2, 3]))
660-
False
661-
>>> is_datetime_arraylike(pd.DatetimeIndex([1, 2, 3]))
662-
True
663-
"""
664-
if isinstance(arr, ABCDatetimeIndex):
665-
return True
666-
elif isinstance(arr, (np.ndarray, ABCSeries)):
667-
return (
668-
is_object_dtype(arr.dtype)
669-
and lib.infer_dtype(arr, skipna=False) == "datetime"
670-
)
671-
return getattr(arr, "inferred_type", None) == "datetime"
672-
673-
674602
def is_dtype_equal(source, target) -> bool:
675603
"""
676604
Check if two dtypes are equal.

pandas/core/generic.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
is_number,
7373
is_numeric_dtype,
7474
is_object_dtype,
75-
is_period_arraylike,
7675
is_re_compilable,
7776
is_scalar,
7877
is_timedelta64_dtype,
@@ -1342,7 +1341,7 @@ def __neg__(self):
13421341

13431342
def __pos__(self):
13441343
values = self._values
1345-
if is_bool_dtype(values) or is_period_arraylike(values):
1344+
if is_bool_dtype(values):
13461345
arr = values
13471346
elif (
13481347
is_numeric_dtype(values)

pandas/core/indexes/accessors.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
is_categorical_dtype,
1010
is_datetime64_dtype,
1111
is_datetime64tz_dtype,
12-
is_datetime_arraylike,
1312
is_integer_dtype,
1413
is_list_like,
15-
is_period_arraylike,
14+
is_period_dtype,
1615
is_timedelta64_dtype,
1716
)
1817
from pandas.core.dtypes.generic import ABCSeries
@@ -50,12 +49,8 @@ def _get_values(self):
5049
elif is_timedelta64_dtype(data.dtype):
5150
return TimedeltaIndex(data, copy=False, name=self.name)
5251

53-
else:
54-
if is_period_arraylike(data):
55-
# TODO: use to_period_array
56-
return PeriodArray(data, copy=False)
57-
if is_datetime_arraylike(data):
58-
return DatetimeIndex(data, copy=False, name=self.name)
52+
elif is_period_dtype(data):
53+
return PeriodArray(data, copy=False)
5954

6055
raise TypeError(
6156
f"cannot convert an object of type {type(data)} to a datetimelike index"
@@ -335,9 +330,7 @@ def __new__(cls, data: "Series"):
335330
return DatetimeProperties(data, orig)
336331
elif is_timedelta64_dtype(data.dtype):
337332
return TimedeltaProperties(data, orig)
338-
elif is_period_arraylike(data):
333+
elif is_period_dtype(data):
339334
return PeriodProperties(data, orig)
340-
elif is_datetime_arraylike(data):
341-
return DatetimeProperties(data, orig)
342335

343336
raise AttributeError("Can only use .dt accessor with datetimelike values")

pandas/tests/dtypes/test_common.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,6 @@ def test_is_string_dtype():
281281
assert com.is_string_dtype(pd.array(["a", "b"], dtype="string"))
282282

283283

284-
def test_is_period_arraylike():
285-
assert not com.is_period_arraylike([1, 2, 3])
286-
assert not com.is_period_arraylike(pd.Index([1, 2, 3]))
287-
assert com.is_period_arraylike(pd.PeriodIndex(["2017-01-01"], freq="D"))
288-
289-
290-
def test_is_datetime_arraylike():
291-
assert not com.is_datetime_arraylike([1, 2, 3])
292-
assert not com.is_datetime_arraylike(pd.Index([1, 2, 3]))
293-
assert com.is_datetime_arraylike(pd.DatetimeIndex([1, 2, 3]))
294-
295-
296284
integer_dtypes: List = []
297285

298286

pandas/tseries/frequencies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from pandas.core.dtypes.common import (
2121
is_datetime64_dtype,
22-
is_period_arraylike,
22+
is_period_dtype,
2323
is_timedelta64_dtype,
2424
)
2525
from pandas.core.dtypes.generic import ABCSeries
@@ -269,7 +269,7 @@ def infer_freq(index, warn: bool = True) -> Optional[str]:
269269
index = values
270270

271271
inferer: _FrequencyInferer
272-
if is_period_arraylike(index):
272+
if is_period_dtype(index):
273273
raise TypeError(
274274
"PeriodIndex given. Check the `freq` attribute "
275275
"instead of using infer_freq."

0 commit comments

Comments
 (0)