You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2019/06/17 16:45:24 UTC
[arrow] branch master updated: ARROW-5606: [Python] deal with
deprecated RangeIndex._start/_stop/_step
This is an automated email from the ASF dual-hosted git repository.
wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new a6f043a ARROW-5606: [Python] deal with deprecated RangeIndex._start/_stop/_step
a6f043a is described below
commit a6f043a19cc75cea65bfe7f312be968926b042f6
Author: Joris Van den Bossche <jo...@gmail.com>
AuthorDate: Mon Jun 17 11:45:15 2019 -0500
ARROW-5606: [Python] deal with deprecated RangeIndex._start/_stop/_step
https://issues.apache.org/jira/browse/ARROW-5606
Author: Joris Van den Bossche <jo...@gmail.com>
Closes #4572 from jorisvandenbossche/ARROW-5606-rangeindex-attributes and squashes the following commits:
1ad113235 <Joris Van den Bossche> add test
2a3ab6cbe <Joris Van den Bossche> ARROW-5606: deal with deprecated RangeIndex._start/_stop/_step
---
python/pyarrow/pandas-shim.pxi | 7 +++++++
python/pyarrow/pandas_compat.py | 9 ++++-----
python/pyarrow/tests/test_pandas.py | 17 ++++++++++++++---
3 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/python/pyarrow/pandas-shim.pxi b/python/pyarrow/pandas-shim.pxi
index e87c829..16e7056 100644
--- a/python/pyarrow/pandas-shim.pxi
+++ b/python/pyarrow/pandas-shim.pxi
@@ -174,6 +174,13 @@ cdef class _PandasAPIShim(object):
self._check_import()
return self._pd.util.testing.assert_frame_equal
+ def get_rangeindex_attribute(self, level, name):
+ # public start/stop/step attributes added in pandas 0.25.0
+ self._check_import()
+ if hasattr(level, name):
+ return getattr(level, name)
+ return getattr(level, '_' + name)
+
cdef _PandasAPIShim pandas_api = _PandasAPIShim()
_pandas_api = pandas_api
diff --git a/python/pyarrow/pandas_compat.py b/python/pyarrow/pandas_compat.py
index 4ec3a56..ea38d41 100644
--- a/python/pyarrow/pandas_compat.py
+++ b/python/pyarrow/pandas_compat.py
@@ -386,14 +386,13 @@ def _get_columns_to_convert(df, schema, preserve_index, columns):
def _get_range_index_descriptor(level):
- # TODO(wesm): Why are these non-public and is there a more public way to
- # get them?
+ # public start/stop/step attributes added in pandas 0.25.0
return {
'kind': 'range',
'name': level.name,
- 'start': level._start,
- 'stop': level._stop,
- 'step': level._step
+ 'start': _pandas_api.get_rangeindex_attribute(level, 'start'),
+ 'stop': _pandas_api.get_rangeindex_attribute(level, 'stop'),
+ 'step': _pandas_api.get_rangeindex_attribute(level, 'step')
}
diff --git a/python/pyarrow/tests/test_pandas.py b/python/pyarrow/tests/test_pandas.py
index 46e4f65..4af3708 100644
--- a/python/pyarrow/tests/test_pandas.py
+++ b/python/pyarrow/tests/test_pandas.py
@@ -33,7 +33,8 @@ import numpy.testing as npt
import pytest
import pytz
-from pyarrow.pandas_compat import get_logical_type
+from pyarrow.pandas_compat import get_logical_type, _pandas_api
+
import pyarrow as pa
try:
@@ -183,15 +184,25 @@ class TestConvertMetadata(object):
result = table.to_pandas()
tm.assert_frame_equal(result, df)
assert isinstance(result.index, pd.RangeIndex)
- assert result.index._step == 2
+ assert _pandas_api.get_rangeindex_attribute(result.index, 'step') == 2
assert result.index.name == index_name
result2 = table_no_index_name.to_pandas()
tm.assert_frame_equal(result2, df2)
assert isinstance(result2.index, pd.RangeIndex)
- assert result2.index._step == 1
+ assert _pandas_api.get_rangeindex_attribute(result2.index, 'step') == 1
assert result2.index.name is None
+ def test_rangeindex_doesnt_warn(self):
+ # ARROW-5606: pandas 0.25 deprecated private _start/stop/step
+ # attributes -> can be removed if support < pd 0.25 is dropped
+ df = pd.DataFrame(np.random.randn(4, 2), columns=['a', 'b'])
+
+ with pytest.warns(None) as record:
+ _check_pandas_roundtrip(df, preserve_index=True)
+
+ assert len(record) == 0
+
def test_multiindex_columns(self):
columns = pd.MultiIndex.from_arrays([
['one', 'two'], ['X', 'Y']