Skip to content

Commit 233aad0

Browse files
committed
add deprecation code
1 parent a86cd9a commit 233aad0

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pandas/core/indexes/range.py

+10
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ def _format_with_header(self, header, na_rep='NaN', **kwargs):
233233
return header + list(map(pprint_thing, self._range))
234234

235235
# --------------------------------------------------------------------
236+
_deprecation_message = ("RangeIndex.{} is deprecated and will be "
237+
"removed in a future version. Use RangeIndex.{} "
238+
"instead")
239+
236240
@cache_readonly
237241
def start(self):
238242
"""
@@ -249,6 +253,8 @@ def _start(self):
249253
.. deprecated:: 0.25.0
250254
Use ``start`` instead.
251255
"""
256+
warnings.warn(self._deprecation_message.format("_start", "start"),
257+
DeprecationWarning, stacklevel=2)
252258
return self.start
253259

254260
@cache_readonly
@@ -267,6 +273,8 @@ def _stop(self):
267273
Use ``stop`` instead.
268274
"""
269275
# GH 25710
276+
warnings.warn(self._deprecation_message.format("_stop", "stop"),
277+
DeprecationWarning, stacklevel=2)
270278
return self.stop
271279

272280
@cache_readonly
@@ -286,6 +294,8 @@ def _step(self):
286294
Use ``step`` instead.
287295
"""
288296
# GH 25710
297+
warnings.warn(self._deprecation_message.format("_step", "step"),
298+
DeprecationWarning, stacklevel=2)
289299
return self.step
290300

291301
@cache_readonly

pandas/tests/indexes/test_range.py

+7
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ def test_start_stop_step_attrs(self, index, start, stop, step):
167167
assert index.stop == stop
168168
assert index.step == step
169169

170+
def test_deprecated_start_stop_step_attrs(self):
171+
# GH 26581
172+
idx = self.create_index()
173+
for attr_name in ['_start', '_stop', '_step']:
174+
with tm.assert_produces_warning(DeprecationWarning):
175+
getattr(idx, attr_name)
176+
170177
def test_copy(self):
171178
i = RangeIndex(5, name='Foo')
172179
i_copy = i.copy()

0 commit comments

Comments
 (0)