Skip to content

Add base test for ExtensionArray.astype and copy #28488

@TomAugspurger

Description

@TomAugspurger

We should be able to test astype to our own type

diff --git a/pandas/tests/extension/base/casting.py b/pandas/tests/extension/base/casting.py index 7146443bf8..b33ab93031 100644 --- a/pandas/tests/extension/base/casting.py +++ b/pandas/tests/extension/base/casting.py @@ -1,3 +1,5 @@ +import pytest + import pandas as pd from pandas.core.internals import ObjectBlock @@ -21,3 +23,9 @@ class BaseCastingTests(BaseExtensionTests): result = pd.Series(data[:5]).astype(str) expected = pd.Series(data[:5].astype(str)) self.assert_series_equal(result, expected) + + @pytest.mark.parametrize('copy', [True, False]) + def test_astype_own_type(self, data, copy): + result = data.astype(data.dtype, copy=copy) + assert (result is data) is (not copy) + self.assert_extension_array_equal(result, data)

A few tests fail this. Would welcome investigation.

$ pytest pandas/tests/extension/ -k test_astype_own_type -v --tb=line

========================================================================= FAILURES ========================================================================== /Users/taugspurger/sandbox/pandas/pandas/tests/extension/base/casting.py:30: AssertionError /Users/taugspurger/sandbox/pandas/pandas/tests/extension/base/casting.py:30: AssertionError /Users/taugspurger/sandbox/pandas/pandas/tests/extension/base/casting.py:30: AssertionError /Users/taugspurger/sandbox/pandas/pandas/tests/extension/base/casting.py:30: AssertionError /Users/taugspurger/sandbox/pandas/pandas/tests/extension/base/casting.py:30: AssertionError /Users/taugspurger/sandbox/pandas/pandas/tests/extension/base/casting.py:30: AssertionError /Users/taugspurger/sandbox/pandas/pandas/tests/extension/base/casting.py:30: AssertionError /Users/taugspurger/sandbox/pandas/pandas/tests/extension/base/casting.py:30: AssertionError /Users/taugspurger/sandbox/pandas/pandas/core/arrays/base.py:390: TypeError: data type not understood /Users/taugspurger/sandbox/pandas/pandas/core/arrays/base.py:390: TypeError: data type not understood /Users/taugspurger/sandbox/pandas/pandas/core/arrays/base.py:390: TypeError: data type not understood /Users/taugspurger/sandbox/pandas/pandas/core/arrays/base.py:390: TypeError: data type not understood /Users/taugspurger/sandbox/pandas/pandas/tests/extension/base/casting.py:30: AssertionError /Users/taugspurger/sandbox/pandas/pandas/tests/extension/base/casting.py:30: AssertionError /Users/taugspurger/sandbox/pandas/pandas/tests/extension/base/casting.py:30: AssertionError /Users/taugspurger/sandbox/pandas/pandas/tests/extension/base/casting.py:30: AssertionError 

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions