CLN: Use is_period_dtype instead of ABCPeriodIndex checks (#22958) · tm9k1/pandas@e756e99 (original) (raw)

`@@ -21,14 +21,15 @@

`

21

21

`is_list_like,

`

22

22

`is_scalar,

`

23

23

`is_bool_dtype,

`

``

24

`+

is_period_dtype,

`

24

25

`is_categorical_dtype,

`

25

26

`is_datetime_or_timedelta_dtype,

`

26

27

`is_float_dtype,

`

27

28

`is_integer_dtype,

`

28

29

`is_object_dtype,

`

29

30

`is_string_dtype)

`

30

31

`from pandas.core.dtypes.generic import (

`

31

``

`-

ABCIndex, ABCSeries, ABCPeriodIndex, ABCIndexClass)

`

``

32

`+

ABCIndex, ABCSeries, ABCIndexClass)

`

32

33

`from pandas.core.dtypes.missing import isna

`

33

34

`from pandas.core import common as com, algorithms, ops

`

34

35

``

`@@ -239,9 +240,8 @@ def equals(self, other):

`

239

240

`# have different timezone

`

240

241

`return False

`

241

242

``

242

``

`-

ToDo: Remove this when PeriodDtype is added

`

243

``

`-

elif isinstance(self, ABCPeriodIndex):

`

244

``

`-

if not isinstance(other, ABCPeriodIndex):

`

``

243

`+

elif is_period_dtype(self):

`

``

244

`+

if not is_period_dtype(other):

`

245

245

`return False

`

246

246

`if self.freq != other.freq:

`

247

247

`return False

`

`@@ -359,7 +359,7 @@ def sort_values(self, return_indexer=False, ascending=True):

`

359

359

`attribs = self._get_attributes_dict()

`

360

360

`freq = attribs['freq']

`

361

361

``

362

``

`-

if freq is not None and not isinstance(self, ABCPeriodIndex):

`

``

362

`+

if freq is not None and not is_period_dtype(self):

`

363

363

`if freq.n > 0 and not ascending:

`

364

364

`freq = freq * -1

`

365

365

`elif freq.n < 0 and ascending:

`

`@@ -386,8 +386,8 @@ def take(self, indices, axis=0, allow_fill=True,

`

386

386

`fill_value=fill_value,

`

387

387

`na_value=iNaT)

`

388

388

``

389

``

`-

keep freq in PeriodIndex, reset otherwise

`

390

``

`-

freq = self.freq if isinstance(self, ABCPeriodIndex) else None

`

``

389

`+

keep freq in PeriodArray/Index, reset otherwise

`

``

390

`+

freq = self.freq if is_period_dtype(self) else None

`

391

391

`return self._shallow_copy(taken, freq=freq)

`

392

392

``

393

393

`_can_hold_na = True

`

`@@ -618,7 +618,7 @@ def repeat(self, repeats, *args, **kwargs):

`

618

618

` Analogous to ndarray.repeat

`

619

619

` """

`

620

620

`nv.validate_repeat(args, kwargs)

`

621

``

`-

if isinstance(self, ABCPeriodIndex):

`

``

621

`+

if is_period_dtype(self):

`

622

622

`freq = self.freq

`

623

623

`else:

`

624

624

`freq = None

`

`@@ -673,7 +673,7 @@ def _concat_same_dtype(self, to_concat, name):

`

673

673

`attribs = self._get_attributes_dict()

`

674

674

`attribs['name'] = name

`

675

675

``

676

``

`-

if not isinstance(self, ABCPeriodIndex):

`

``

676

`+

if not is_period_dtype(self):

`

677

677

`# reset freq

`

678

678

`attribs['freq'] = None

`

679

679

``