Skip to content

Commit 123013c

Browse files
committed
Changes
1 parent a5b3904 commit 123013c

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

doc/source/whatsnew/v0.25.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ Other Deprecations
370370
- Deprecated the ``units=M`` (months) and ``units=Y`` (year) parameters for ``units`` of :func:`pandas.to_timedelta`, :func:`pandas.Timedelta` and :func:`pandas.TimedeltaIndex` (:issue:`16344`)
371371
- The :attr:`SparseArray.values` attribute is deprecated. You can use ``np.asarray(...)`` or
372372
the :meth:`SparseArray.to_dense` method instead (:issue:`26421`).
373+
- The internal attributes ``_start``, ``_stop`` and ``_step`` attributes of :class:`RangeIndex` have been deprecated.
374+
Use the public attributes :attr:`~RangeIndex.start`, :attr:`~RangeIndex.stop` and :attr:`~RangeIndex.step` instead (:issue:`26581`).
373375
- The functions :func:`pandas.to_datetime` and :func:`pandas.to_timedelta` have deprecated the ``box`` keyword. Instead, use :meth:`to_numpy` or :meth:`Timestamp.to_datetime64` or :meth:`Timedelta.to_timedelta64`. (:issue:`24416`)
374376
- The :meth:`DataFrame.compound` and :meth:`Series.compound` methods are deprecated and will be removed in a future version (:issue:`26405`).
375377

pandas/core/indexes/range.py

+21-23
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def _start(self):
230230
The value of the `start` parameter (or ``0`` if this was not supplied)
231231
232232
.. deprecated:: 0.25.0
233-
Use ._range.start or .start instead.
233+
Use ``.start`` instead.
234234
"""
235235
return self._range.start
236236

@@ -247,7 +247,7 @@ def _stop(self):
247247
The value of the `stop` parameter
248248
249249
.. deprecated:: 0.25.0
250-
Use ._range.stop or .stop instead.
250+
Use ``.stop`` instead.
251251
"""
252252
# GH 25710
253253
return self._range.stop
@@ -266,7 +266,7 @@ def _step(self):
266266
The value of the `step` parameter (or ``1`` if this was not supplied)
267267
268268
.. deprecated:: 0.25.0
269-
Use ._range.step or .step instead.
269+
Use ``.step`` instead.
270270
"""
271271
# GH 25710
272272
return self._range.step
@@ -333,8 +333,8 @@ def tolist(self):
333333
def _shallow_copy(self, values=None, **kwargs):
334334
if values is None:
335335
name = kwargs.get("name", self.name)
336-
return RangeIndex._simple_new(
337-
name=name, **dict(self._get_data_as_items()))
336+
return self._simple_new(name=name,
337+
**dict(self._get_data_as_items()))
338338
else:
339339
kwargs.setdefault('name', self.name)
340340
return self._int64index._shallow_copy(values, **kwargs)
@@ -344,7 +344,7 @@ def copy(self, name=None, deep=False, dtype=None, **kwargs):
344344
self._validate_dtype(dtype)
345345
if name is None:
346346
name = self.name
347-
return RangeIndex.from_range(self._range, name=name)
347+
return self.from_range(self._range, name=name)
348348

349349
def _minmax(self, meth):
350350
no_steps = len(self) - 1
@@ -426,7 +426,7 @@ def intersection(self, other, sort=False):
426426
return super().intersection(other, sort=sort)
427427

428428
if not len(self) or not len(other):
429-
return RangeIndex._simple_new(None)
429+
return self._simple_new(None)
430430

431431
first = self._range[::-1] if self.step < 0 else self._range
432432
second = other._range[::-1] if other.step < 0 else other._range
@@ -436,7 +436,7 @@ def intersection(self, other, sort=False):
436436
int_low = max(first.start, second.start)
437437
int_high = min(first.stop, second.stop)
438438
if int_high <= int_low:
439-
return RangeIndex._simple_new(None)
439+
return self._simple_new(None)
440440

441441
# Method hint: linear Diophantine equation
442442
# solve intersection problem
@@ -446,20 +446,18 @@ def intersection(self, other, sort=False):
446446

447447
# check whether element sets intersect
448448
if (first.start - second.start) % gcd:
449-
return RangeIndex._simple_new(None)
449+
return self._simple_new(None)
450450

451451
# calculate parameters for the RangeIndex describing the
452452
# intersection disregarding the lower bounds
453453
tmp_start = first.start + (second.start - first.start) * \
454454
first.step // gcd * s
455455
new_step = first.step * second.step // gcd
456-
new_index = RangeIndex._simple_new(tmp_start, int_high, new_step)
456+
new_index = self._simple_new(tmp_start, int_high, new_step)
457457

458458
# adjust index to limiting interval
459459
new_start = new_index._min_fitting_element(int_low)
460-
new_index = RangeIndex._simple_new(new_start,
461-
new_index.stop,
462-
new_index.step)
460+
new_index = self._simple_new(new_start, new_index.stop, new_index.step)
463461

464462
if (self.step < 0 and other.step < 0) is not (new_index.step < 0):
465463
new_index = new_index[::-1]
@@ -538,21 +536,23 @@ def _union(self, other, sort):
538536
if ((start_s - start_o) % step_s == 0 and
539537
(start_s - end_o) <= step_s and
540538
(start_o - end_s) <= step_s):
541-
return RangeIndex(start_r, end_r + step_s, step_s)
539+
return self.__class__(start_r, end_r + step_s, step_s)
542540
if ((step_s % 2 == 0) and
543541
(abs(start_s - start_o) <= step_s / 2) and
544542
(abs(end_s - end_o) <= step_s / 2)):
545-
return RangeIndex(start_r, end_r + step_s / 2, step_s / 2)
543+
return self.__class__(start_r,
544+
end_r + step_s / 2,
545+
step_s / 2)
546546
elif step_o % step_s == 0:
547547
if ((start_o - start_s) % step_s == 0 and
548548
(start_o + step_s >= start_s) and
549549
(end_o - step_s <= end_s)):
550-
return RangeIndex(start_r, end_r + step_s, step_s)
550+
return self.__class__(start_r, end_r + step_s, step_s)
551551
elif step_s % step_o == 0:
552552
if ((start_s - start_o) % step_o == 0 and
553553
(start_s + step_o >= start_o) and
554554
(end_s - step_o <= end_o)):
555-
return RangeIndex(start_r, end_r + step_o, step_o)
555+
return self.__class__(start_r, end_r + step_o, step_o)
556556
return self._int64index._union(other, sort=sort)
557557

558558
@Appender(_index_shared_docs['join'])
@@ -601,7 +601,7 @@ def __getitem__(self, key):
601601
size=len(self)))
602602
if isinstance(key, slice):
603603
new_range = self._range[key]
604-
return RangeIndex.from_range(new_range, name=self.name)
604+
return self.from_range(new_range, name=self.name)
605605

606606
# fall back to Int64Index
607607
return super_getitem(key)
@@ -617,12 +617,10 @@ def __floordiv__(self, other):
617617
start = self.start // other
618618
step = self.step // other
619619
stop = start + len(self) * step
620-
return RangeIndex._simple_new(
621-
start, stop, step, name=self.name)
620+
return self._simple_new( start, stop, step, name=self.name)
622621
if len(self) == 1:
623622
start = self.start // other
624-
return RangeIndex._simple_new(
625-
start, start + 1, 1, name=self.name)
623+
return self._simple_new(start, start + 1, 1, name=self.name)
626624
return self._int64index // other
627625

628626
@classmethod
@@ -678,7 +676,7 @@ def _evaluate_numeric_binop(self, other):
678676
rstart = op(left.start, right)
679677
rstop = op(left.stop, right)
680678

681-
result = RangeIndex(rstart, rstop, rstep, **attrs)
679+
result = cls(rstart, rstop, rstep, **attrs)
682680

683681
# for compat with numpy / Int64Index
684682
# even if we can represent as a RangeIndex, return

0 commit comments

Comments
 (0)