jorisvandenbossche commented on a change in pull request #12178:
URL: https://github.com/apache/arrow/pull/12178#discussion_r803433525
##########
File path: python/pyarrow/tests/test_pandas.py
##########
@@ -4082,16 +4082,52 @@ def test_array_to_pandas():
# tm.assert_series_equal(result, expected)
-def test_roundtrip_empty_table_with_extension_dtype_index():
+def test_array_to_pandas_types_mapper():
+ # https://issues.apache.org/jira/browse/ARROW-9664
if Version(pd.__version__) < Version("1.0.0"):
pytest.skip("ExtensionDtype to_pandas method missing")
- df = pd.DataFrame(index=pd.interval_range(start=0, end=3))
- table = pa.table(df)
- table.to_pandas().index == pd.Index([{'left': 0, 'right': 1},
- {'left': 1, 'right': 2},
- {'left': 2, 'right': 3}],
- dtype='object')
+ data = pa.array([1, 2, 3], pa.int64())
+
+ # Test with mapper function
+ types_mapper = {pa.int64(): pd.Int64Dtype()}.get
+ result = data.to_pandas(types_mapper=types_mapper)
+ assert result.dtype == types_mapper(data.type)
+
+ # Test mapper function returning None
+ types_mapper = {pa.int64(): None}.get
+ result = data.to_pandas(types_mapper=types_mapper)
+ assert result.dtype == data.type.to_pandas_dtype()
+
+ # Test mapper function not containing the dtype
+ types_mapper = {pa.float64(): pd.Float64Dtype()}.get
+ result = data.to_pandas(types_mapper=types_mapper)
+ assert result.dtype == data.type.to_pandas_dtype()
Review comment:
```suggestion
assert result.dtype == np.dtype("int64")
```
Just to make it a bit more explicit for someone reading the test
##########
File path: python/pyarrow/tests/test_pandas.py
##########
@@ -4082,16 +4082,52 @@ def test_array_to_pandas():
# tm.assert_series_equal(result, expected)
-def test_roundtrip_empty_table_with_extension_dtype_index():
+def test_array_to_pandas_types_mapper():
+ # https://issues.apache.org/jira/browse/ARROW-9664
if Version(pd.__version__) < Version("1.0.0"):
pytest.skip("ExtensionDtype to_pandas method missing")
- df = pd.DataFrame(index=pd.interval_range(start=0, end=3))
- table = pa.table(df)
- table.to_pandas().index == pd.Index([{'left': 0, 'right': 1},
- {'left': 1, 'right': 2},
- {'left': 2, 'right': 3}],
- dtype='object')
+ data = pa.array([1, 2, 3], pa.int64())
+
+ # Test with mapper function
+ types_mapper = {pa.int64(): pd.Int64Dtype()}.get
+ result = data.to_pandas(types_mapper=types_mapper)
+ assert result.dtype == types_mapper(data.type)
Review comment:
```suggestion
assert result.dtype == pd.Int64Dtype()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]