Skip to content

Commit dee54ed

Browse files
committed
Changes.
1 parent cada73f commit dee54ed

File tree

5 files changed

+44
-44
lines changed

5 files changed

+44
-44
lines changed

doc/source/whatsnew/v0.25.0.rst

+3
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ Other Deprecations
472472
the :meth:`SparseArray.to_dense` method instead (:issue:`26421`).
473473
- 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`)
474474
- The :meth:`DataFrame.compound` and :meth:`Series.compound` methods are deprecated and will be removed in a future version (:issue:`26405`).
475+
- The internal attributes ``_start``, ``_stop`` and ``_step`` attributes of :class:`RangeIndex` have been deprecated.
476+
Use the public attributes :attr:`~RangeIndex.start`, :attr:`~RangeIndex.stop` and :attr:`~RangeIndex.step` instead (:issue:`26581`).
477+
475478

476479
.. _whatsnew_0250.prior_deprecations:
477480

pandas/core/frame.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -2282,7 +2282,7 @@ def info(self, verbose=None, buf=None, max_cols=None, memory_usage=None,
22822282
text_col 5 non-null object
22832283
float_col 5 non-null float64
22842284
dtypes: float64(1), int64(1), object(1)
2285-
memory usage: 312.0+ bytes
2285+
memory usage: 248.0+ bytes
22862286
22872287
Prints a summary of columns count and its dtypes but not per column
22882288
information:
@@ -2292,7 +2292,7 @@ def info(self, verbose=None, buf=None, max_cols=None, memory_usage=None,
22922292
RangeIndex: 5 entries, 0 to 4
22932293
Columns: 3 entries, int_col to float_col
22942294
dtypes: float64(1), int64(1), object(1)
2295-
memory usage: 312.0+ bytes
2295+
memory usage: 248.0+ bytes
22962296
22972297
Pipe output of DataFrame.info to buffer instead of sys.stdout, get
22982298
buffer content and writes to a text file:
@@ -2494,7 +2494,7 @@ def memory_usage(self, index=True, deep=False):
24942494
4 1 1.0 1.0+0.0j 1 True
24952495
24962496
>>> df.memory_usage()
2497-
Index 192
2497+
Index 128
24982498
int64 40000
24992499
float64 40000
25002500
complex128 80000
@@ -2513,7 +2513,7 @@ def memory_usage(self, index=True, deep=False):
25132513
The memory footprint of `object` dtype columns is ignored by default:
25142514
25152515
>>> df.memory_usage(deep=True)
2516-
Index 192
2516+
Index 128
25172517
int64 40000
25182518
float64 40000
25192519
complex128 80000
@@ -2525,7 +2525,7 @@ def memory_usage(self, index=True, deep=False):
25252525
many repeated values.
25262526
25272527
>>> df['object'].astype('category').memory_usage(deep=True)
2528-
5280
2528+
5216ser
25292529
"""
25302530
result = Series([c.memory_usage(index=False, deep=deep)
25312531
for col, c in self.iteritems()], index=self.columns)

pandas/core/indexes/range.py

+29-33
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ def _simple_new(cls, start, stop=None, step=None, name=None,
167167
for k, v in kwargs.items():
168168
setattr(result, k, v)
169169

170-
result._range = range(result._start, result._stop, result._step)
171-
172170
result._reset_identity()
173171
return result
174172

@@ -238,20 +236,20 @@ def _format_with_header(self, header, na_rep='NaN', **kwargs):
238236
@cache_readonly
239237
def start(self):
240238
"""
241-
The value of the `start` parameter (or ``0`` if this was not supplied)
239+
The value of the `start` parameter (``0`` if this was not supplied)
242240
"""
243241
# GH 25710
244242
return self._range.start
245243

246244
@property
247245
def _start(self):
248246
"""
249-
The value of the `start` parameter (or ``0`` if this was not supplied)
247+
The value of the `start` parameter (``0`` if this was not supplied)
250248
251249
.. deprecated:: 0.25.0
252-
Use ._range.start or .start instead.
250+
Use ``start`` instead.
253251
"""
254-
return self._range.start
252+
return self.start
255253

256254
@cache_readonly
257255
def stop(self):
@@ -266,38 +264,38 @@ def _stop(self):
266264
The value of the `stop` parameter
267265
268266
.. deprecated:: 0.25.0
269-
Use ._range.stop or .stop instead.
267+
Use ``stop`` instead.
270268
"""
271269
# GH 25710
272-
return self._range.stop
270+
return self.stop
273271

274272
@cache_readonly
275273
def step(self):
276274
"""
277-
The value of the `step` parameter (or ``1`` if this was not supplied)
275+
The value of the `step` parameter (``1`` if this was not supplied)
278276
"""
279277
# GH 25710
280278
return self._range.step
281279

282280
@property
283281
def _step(self):
284282
"""
285-
The value of the `step` parameter (or ``1`` if this was not supplied)
283+
The value of the `step` parameter (``1`` if this was not supplied)
286284
287285
.. deprecated:: 0.25.0
288-
Use ._range.step or .step instead.
286+
Use ``step`` instead.
289287
"""
290288
# GH 25710
291-
return self._range.step
289+
return self.step
292290

293291
@cache_readonly
294292
def nbytes(self):
295293
"""
296294
Return the number of bytes in the underlying data.
297295
"""
298296
rng = self._range
299-
return getsizeof(rng) + sum(getsizeof(rng, v)
300-
for v in ['start', 'stop', 'step'])
297+
return getsizeof(rng) + sum(getsizeof(getattr(rng, attr_name))
298+
for attr_name in ['start', 'stop', 'step'])
301299

302300
def memory_usage(self, deep=False):
303301
"""
@@ -361,7 +359,7 @@ def tolist(self):
361359
def _shallow_copy(self, values=None, **kwargs):
362360
if values is None:
363361
name = kwargs.get("name", self.name)
364-
return RangeIndex._simple_new(
362+
return self._simple_new(
365363
name=name, **dict(self._get_data_as_items()))
366364
else:
367365
kwargs.setdefault('name', self.name)
@@ -372,7 +370,7 @@ def copy(self, name=None, deep=False, dtype=None, **kwargs):
372370
self._validate_dtype(dtype)
373371
if name is None:
374372
name = self.name
375-
return RangeIndex.from_range(self._range, name=name)
373+
return self.from_range(self._range, name=name)
376374

377375
def _minmax(self, meth):
378376
no_steps = len(self) - 1
@@ -454,7 +452,7 @@ def intersection(self, other, sort=False):
454452
return super().intersection(other, sort=sort)
455453

456454
if not len(self) or not len(other):
457-
return RangeIndex._simple_new(None)
455+
return self._simple_new(None)
458456

459457
first = self._range[::-1] if self.step < 0 else self._range
460458
second = other._range[::-1] if other.step < 0 else other._range
@@ -464,7 +462,7 @@ def intersection(self, other, sort=False):
464462
int_low = max(first.start, second.start)
465463
int_high = min(first.stop, second.stop)
466464
if int_high <= int_low:
467-
return RangeIndex._simple_new(None)
465+
return self._simple_new(None)
468466

469467
# Method hint: linear Diophantine equation
470468
# solve intersection problem
@@ -474,20 +472,18 @@ def intersection(self, other, sort=False):
474472

475473
# check whether element sets intersect
476474
if (first.start - second.start) % gcd:
477-
return RangeIndex._simple_new(None)
475+
return self._simple_new(None)
478476

479477
# calculate parameters for the RangeIndex describing the
480478
# intersection disregarding the lower bounds
481479
tmp_start = first.start + (second.start - first.start) * \
482480
first.step // gcd * s
483481
new_step = first.step * second.step // gcd
484-
new_index = RangeIndex._simple_new(tmp_start, int_high, new_step)
482+
new_index = self._simple_new(tmp_start, int_high, new_step)
485483

486484
# adjust index to limiting interval
487485
new_start = new_index._min_fitting_element(int_low)
488-
new_index = RangeIndex._simple_new(new_start,
489-
new_index.stop,
490-
new_index.step)
486+
new_index = self._simple_new(new_start, new_index.stop, new_index.step)
491487

492488
if (self.step < 0 and other.step < 0) is not (new_index.step < 0):
493489
new_index = new_index[::-1]
@@ -566,21 +562,23 @@ def _union(self, other, sort):
566562
if ((start_s - start_o) % step_s == 0 and
567563
(start_s - end_o) <= step_s and
568564
(start_o - end_s) <= step_s):
569-
return RangeIndex(start_r, end_r + step_s, step_s)
565+
return self.__class__(start_r, end_r + step_s, step_s)
570566
if ((step_s % 2 == 0) and
571567
(abs(start_s - start_o) <= step_s / 2) and
572568
(abs(end_s - end_o) <= step_s / 2)):
573-
return RangeIndex(start_r, end_r + step_s / 2, step_s / 2)
569+
return self.__class__(start_r,
570+
end_r + step_s / 2,
571+
step_s / 2)
574572
elif step_o % step_s == 0:
575573
if ((start_o - start_s) % step_s == 0 and
576574
(start_o + step_s >= start_s) and
577575
(end_o - step_s <= end_s)):
578-
return RangeIndex(start_r, end_r + step_s, step_s)
576+
return self.__class__(start_r, end_r + step_s, step_s)
579577
elif step_s % step_o == 0:
580578
if ((start_s - start_o) % step_o == 0 and
581579
(start_s + step_o >= start_o) and
582580
(end_s - step_o <= end_o)):
583-
return RangeIndex(start_r, end_r + step_o, step_o)
581+
return self.__class__(start_r, end_r + step_o, step_o)
584582
return self._int64index._union(other, sort=sort)
585583

586584
@Appender(_index_shared_docs['join'])
@@ -629,7 +627,7 @@ def __getitem__(self, key):
629627
size=len(self)))
630628
if isinstance(key, slice):
631629
new_range = self._range[key]
632-
return RangeIndex.from_range(new_range, name=self.name)
630+
return self.from_range(new_range, name=self.name)
633631

634632
# fall back to Int64Index
635633
return super_getitem(key)
@@ -645,12 +643,10 @@ def __floordiv__(self, other):
645643
start = self.start // other
646644
step = self.step // other
647645
stop = start + len(self) * step
648-
return RangeIndex._simple_new(
649-
start, stop, step, name=self.name)
646+
return self._simple_new(start, stop, step, name=self.name)
650647
if len(self) == 1:
651648
start = self.start // other
652-
return RangeIndex._simple_new(
653-
start, start + 1, 1, name=self.name)
649+
return self._simple_new(start, start + 1, 1, name=self.name)
654650
return self._int64index // other
655651

656652
@classmethod
@@ -706,7 +702,7 @@ def _evaluate_numeric_binop(self, other):
706702
rstart = op(left.start, right)
707703
rstop = op(left.stop, right)
708704

709-
result = RangeIndex(rstart, rstop, rstep, **attrs)
705+
result = self.__class__(rstart, rstop, rstep, **attrs)
710706

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

pandas/core/series.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4010,7 +4010,7 @@ def memory_usage(self, index=True, deep=False):
40104010
--------
40114011
>>> s = pd.Series(range(3))
40124012
>>> s.memory_usage()
4013-
216
4013+
152
40144014
40154015
Not including the index gives the size of the rest of the data, which
40164016
is necessarily smaller:
@@ -4024,9 +4024,9 @@ def memory_usage(self, index=True, deep=False):
40244024
>>> s.values
40254025
array(['a', 'b'], dtype=object)
40264026
>>> s.memory_usage()
4027-
208
4027+
144
40284028
>>> s.memory_usage(deep=True)
4029-
324
4029+
260
40304030
"""
40314031
v = super().memory_usage(deep=deep)
40324032
if index:

pandas/tests/indexes/test_range.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,9 @@ def test_dtype(self):
239239

240240
def test_cached_data(self):
241241
# GH 26565
242-
# Calling RangeIndex._data caches an int64 array of the same length at
243-
# self._cached_data. This tests whether _cached_data has been set.
242+
# Calling RangeIndex._data caches an int64 array of the same length as
243+
# self at self._cached_data.
244+
# This tests whether _cached_data is being set by various operations.
244245
idx = RangeIndex(0, 100, 10)
245246

246247
assert idx._cached_data is None
@@ -269,7 +270,7 @@ def test_cached_data(self):
269270
df.iloc[5:10]
270271
assert idx._cached_data is None
271272

272-
# actually calling data._data
273+
# actually calling idx._data
273274
assert isinstance(idx._data, np.ndarray)
274275
assert isinstance(idx._cached_data, np.ndarray)
275276

0 commit comments

Comments
 (0)