Skip to content

Commit 518315c

Browse files
committed
seperate file
1 parent 642b01a commit 518315c

File tree

3 files changed

+325
-113
lines changed

3 files changed

+325
-113
lines changed
Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,38 @@
1+
import numpy as np
12
import pytest
23

3-
# A set of Base EA tests that are know to not work for
4-
# the object-dtype PandasArray holding nested data.
5-
skips = {
6-
'TestCasting.test_astype_str',
7-
'TestConstructors.test_array_from_scalars',
8-
# tuple isn't instance of np.object
9-
'TestGetitem.test_getitem_scalar',
10-
# Can't pass tuples to _from_sequence
11-
'TestGetitem.test_take_series',
12-
# np.array shape inference
13-
'TestInterface.test_array_interface',
14-
# Can't construct expected.
15-
'TestMethods.test_unique',
16-
'TestMethods.test_combine_add',
17-
'TestMethods.test_shift_fill_value',
18-
'TestMethods.test_where_series',
19-
'TestMethods.test_repeat',
20-
# Can't hash ndarray[tuple]
21-
'TestMethods.test_hash_pandas_object_works',
22-
# Can't construct expected.
23-
'TestReshaping.test_merge',
24-
'TestReshaping.test_merge_on_extension_array',
25-
'TestReshaping.test_merge_on_extension_array_duplicates',
26-
27-
# ndarray setting
28-
'TestSetitem.test_setitem_scalar_series',
29-
'TestSetitem.test_setitem_sequence',
30-
'TestSetitem.test_setitem_sequence_mismatched_length_raises',
31-
'TestSetitem.test_setitem_sequence_broadcasts',
32-
'TestSetitem.test_setitem_sequence_broadcasts',
33-
'TestSetitem.test_setitem_loc_scalar_mixed',
34-
'TestSetitem.test_setitem_iloc_scalar_mixed',
35-
'TestSetitem.test_setitem_loc_scalar_multiple_homogoneous',
36-
'TestSetitem.test_setitem_iloc_scalar_multiple_homogoneous',
37-
'TestSetitem.test_setitem_mask_broadcast',
38-
'TestSetitem.test_setitem_scalar_key_sequence_raise',
39-
40-
# parsing differs.
41-
'TestParsing.test_EA_types',
42-
}
43-
44-
45-
def pytest_collection_modifyitems(config, items):
46-
skip = pytest.mark.skip(reason="Skipping for nested data.")
47-
for item in items:
48-
# TODO: See if pytest has a better way to resolve the *value*
49-
# supplied to a fixture. Right now .keywords gets things
50-
# like 'object' or 'data-object'.
51-
parts = item.name.split("[")
52-
qualname = item.parent.obj.__class__.__name__ + '.' + item.obj.__name__
53-
if (len(parts) > 1 and 'object' in item.name.split('[')[1]
54-
and qualname in skips):
55-
item.add_marker(skip)
4+
from pandas.core.arrays.numpy_ import PandasArray
5+
6+
7+
@pytest.fixture
8+
def allow_in_pandas(monkeypatch):
9+
"""
10+
A monkeypatch to tells pandas to let us in.
11+
12+
By default, passing a PandasArray to an index / series / frame
13+
constructor will unbox that PandasArray to an ndarray, and treat
14+
it as a non-EA column. We don't want people using EAs without
15+
reason.
16+
17+
The mechanism for this is a check against ABCPandasArray
18+
in each constructor.
19+
20+
But, for testing, we need to allow them in pandas. So we patch
21+
the _typ of PandasArray, so that we evade the ABCPandasArray
22+
check.
23+
"""
24+
with monkeypatch.context() as m:
25+
m.setattr(PandasArray, '_typ', 'extension')
26+
yield
27+
28+
29+
@pytest.fixture
30+
def na_value():
31+
return np.nan
32+
33+
34+
@pytest.fixture
35+
def na_cmp():
36+
def cmp(a, b):
37+
return np.isnan(a) and np.isnan(b)
38+
return cmp

pandas/tests/extension/numpy_/test_numpy.py

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,13 @@
99
from .. import base
1010

1111

12-
@pytest.fixture(params=['float', 'object'])
13-
def dtype(request):
14-
return PandasDtype(np.dtype(request.param))
15-
16-
1712
@pytest.fixture
18-
def allow_in_pandas(monkeypatch):
19-
"""
20-
A monkeypatch to tells pandas to let us in.
21-
22-
By default, passing a PandasArray to an index / series / frame
23-
constructor will unbox that PandasArray to an ndarray, and treat
24-
it as a non-EA column. We don't want people using EAs without
25-
reason.
26-
27-
The mechanism for this is a check against ABCPandasArray
28-
in each constructor.
29-
30-
But, for testing, we need to allow them in pandas. So we patch
31-
the _typ of PandasArray, so that we evade the ABCPandasArray
32-
check.
33-
"""
34-
with monkeypatch.context() as m:
35-
m.setattr(PandasArray, '_typ', 'extension')
36-
yield
13+
def dtype():
14+
return PandasDtype(np.dtype('float'))
3715

3816

3917
@pytest.fixture
4018
def data(allow_in_pandas, dtype):
41-
if dtype.numpy_dtype == 'object':
42-
return pd.Series([(i,) for i in range(100)]).array
4319
return PandasArray(np.arange(1, 101, dtype=dtype._dtype))
4420

4521

@@ -48,18 +24,6 @@ def data_missing(allow_in_pandas):
4824
return PandasArray(np.array([np.nan, 1.0]))
4925

5026

51-
@pytest.fixture
52-
def na_value():
53-
return np.nan
54-
55-
56-
@pytest.fixture
57-
def na_cmp():
58-
def cmp(a, b):
59-
return np.isnan(a) and np.isnan(b)
60-
return cmp
61-
62-
6327
@pytest.fixture
6428
def data_for_sorting(allow_in_pandas):
6529
"""Length-3 array with a known sort order.
@@ -152,19 +116,6 @@ class TestArithmetics(BaseNumPyTests, base.BaseArithmeticOpsTests):
152116
frame_scalar_exc = None
153117
series_array_exc = None
154118

155-
def _check_op(self, s, op, other, op_name, exc=NotImplementedError):
156-
if s.dtype == 'object':
157-
raise pytest.skip("Skipping for object dtype.")
158-
super(TestArithmetics, self)._check_op(s, op, other, op_name, exc)
159-
160-
def _check_divmod_op(self, s, op, other, exc=Exception):
161-
if isinstance(s, pd.Series) and s.dtype == 'object':
162-
raise pytest.skip("Skipping for object dtype.")
163-
elif isinstance(other, pd.Series) and other.dtype == 'object':
164-
raise pytest.skip("Skipping for object dtype.")
165-
166-
super(TestArithmetics, self)._check_divmod_op(s, op, other, exc)
167-
168119
def test_divmod_series_array(self, data):
169120
s = pd.Series(data)
170121
self._check_divmod_op(s, divmod, data, exc=None)
@@ -201,24 +152,17 @@ class TestPrinting(BaseNumPyTests, base.BasePrintingTests):
201152
class TestNumericReduce(BaseNumPyTests, base.BaseNumericReduceTests):
202153

203154
def check_reduce(self, s, op_name, skipna):
204-
if s.dtype == 'object':
205-
raise pytest.skip("Skipping for object dtype.")
206155
result = getattr(s, op_name)(skipna=skipna)
207156
# avoid coercing int -> float. Just cast to the actual numpy type.
208157
expected = getattr(s.astype(s.dtype._dtype), op_name)(skipna=skipna)
209158
tm.assert_almost_equal(result, expected)
210159

211160

212161
class TestBooleanReduce(BaseNumPyTests, base.BaseBooleanReduceTests):
213-
214-
def check_reduce(self, s, op_name, skipna):
215-
if s.dtype == 'object':
216-
raise pytest.skip("Skipping for object dtype.")
217-
218-
super(TestBooleanReduce, self).check_reduce(s, op_name, skipna)
162+
pass
219163

220164

221-
class TestMissing(BaseNumPyTests, base.BaseMissingTests):
165+
class TestMising(BaseNumPyTests, base.BaseMissingTests):
222166
pass
223167

224168

0 commit comments

Comments
 (0)