Skip to content

Commit 0a88875

Browse files
committed
REF: make _concat methods @classmethods
1 parent 576a696 commit 0a88875

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

pandas/core/indexes/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,7 @@ def append(self, other):
16851685
res.name = name
16861686
return res
16871687

1688+
@classmethod
16881689
def _concat(self, to_concat):
16891690
"""
16901691
Concatenate to_concat to single Index
@@ -1695,7 +1696,8 @@ def _concat(self, to_concat):
16951696
else:
16961697
return _concat._concat_index_asobject(to_concat)
16971698

1698-
def _concat_same_dtype(self, to_concat):
1699+
@classmethod
1700+
def _concat_same_dtype(cls, to_concat):
16991701
"""
17001702
Concatenate to_concat which has the same dtype
17011703
"""

pandas/core/indexes/category.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -622,14 +622,15 @@ def insert(self, loc, item):
622622
codes = np.concatenate((codes[:loc], code, codes[loc:]))
623623
return self._create_from_codes(codes)
624624

625-
def _concat_same_dtype(self, to_concat):
625+
@classmethod
626+
def _concat_same_dtype(cls, to_concat):
626627
"""
627628
Concatenate to_concat which has the same class
628629
ValueError if other is not in the categories
629630
"""
630-
to_concat = [self._is_dtype_compat(c) for c in to_concat]
631-
codes = np.concatenate([c.codes for c in to_concat])
632-
return self._create_from_codes(codes)
631+
compat = [to_concat[0]._is_dtype_compat(c) for c in to_concat]
632+
codes = np.concatenate([c.codes for c in compat])
633+
return to_concat[0]._create_from_codes(codes)
633634

634635
def _codes_for_groupby(self, sort):
635636
""" Return a Categorical adjusted for groupby """

pandas/core/indexes/range.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,11 @@ def join(self, other, how='left', level=None, return_indexers=False,
443443
return super(RangeIndex, self).join(other, how, level, return_indexers,
444444
sort)
445445

446-
def _concat_same_dtype(self, indexes):
446+
@classmethod
447+
def _concat_same_dtype(cls, indexes):
447448

448449
if not all([isinstance(i, RangeIndex) for i in indexes]):
449-
return super(RangeIndex, self)._concat_same_dtype(indexes)
450+
return super(RangeIndex, cls)._concat_same_dtype(indexes)
450451

451452
start = step = next = None
452453

@@ -462,13 +463,13 @@ def _concat_same_dtype(self, indexes):
462463
elif step is None:
463464
# First non-empty index had only one element
464465
if obj._start == start:
465-
return super(RangeIndex, self)._concat_same_dtype(indexes)
466+
return super(RangeIndex, cls)._concat_same_dtype(indexes)
466467
step = obj._start - start
467468

468469
non_consecutive = ((step != obj._step and len(obj) > 1) or
469470
(next is not None and obj._start != next))
470471
if non_consecutive:
471-
return super(RangeIndex, self)._concat_same_dtype(indexes)
472+
return super(RangeIndex, cls)._concat_same_dtype(indexes)
472473

473474
if step is not None:
474475
next = obj[-1] + step

0 commit comments

Comments
 (0)