forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_panel.py
95 lines (72 loc) · 2.87 KB
/
test_panel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# -*- coding: utf-8 -*-
# pylint: disable-msg=E1101,W0612
from warnings import catch_warnings
import pytest
from pandas import Panel, Panel4D
from pandas.util.testing import (assert_panel_equal,
assert_panel4d_equal,
assert_almost_equal)
import pandas.util.testing as tm
import pandas.util._test_decorators as td
from .test_generic import Generic
class TestPanel(Generic):
_typ = Panel
_comparator = lambda self, x, y: assert_panel_equal(x, y, by_blocks=True)
@td.skip_if_no('xarray', min_version='0.7.0')
def test_to_xarray(self):
from xarray import DataArray
with catch_warnings(record=True):
p = tm.makePanel()
result = p.to_xarray()
assert isinstance(result, DataArray)
assert len(result.coords) == 3
assert_almost_equal(list(result.coords.keys()),
['items', 'major_axis', 'minor_axis'])
assert len(result.dims) == 3
# idempotency
assert_panel_equal(result.to_pandas(), p)
class TestPanel4D(Generic):
_typ = Panel4D
_comparator = lambda self, x, y: assert_panel4d_equal(x, y, by_blocks=True)
def test_sample(self):
pytest.skip("sample on Panel4D")
@td.skip_if_no('xarray', min_version='0.7.0')
def test_to_xarray(self):
from xarray import DataArray
with catch_warnings(record=True):
p = tm.makePanel4D()
result = p.to_xarray()
assert isinstance(result, DataArray)
assert len(result.coords) == 4
assert_almost_equal(list(result.coords.keys()),
['labels', 'items', 'major_axis',
'minor_axis'])
assert len(result.dims) == 4
# non-convertible
pytest.raises(ValueError, lambda: result.to_pandas())
# run all the tests, but wrap each in a warning catcher
for t in ['test_rename', 'test_get_numeric_data',
'test_get_default', 'test_nonzero',
'test_downcast', 'test_constructor_compound_dtypes',
'test_head_tail',
'test_size_compat', 'test_split_compat',
'test_unexpected_keyword',
'test_stat_unexpected_keyword', 'test_api_compat',
'test_stat_non_defaults_args',
'test_truncate_out_of_bounds',
'test_metadata_propagation', 'test_copy_and_deepcopy',
'test_sample']:
def f():
def tester(self):
f = getattr(super(TestPanel, self), t)
with catch_warnings(record=True):
f()
return tester
setattr(TestPanel, t, f())
def f():
def tester(self):
f = getattr(super(TestPanel4D, self), t)
with catch_warnings(record=True):
f()
return tester
setattr(TestPanel4D, t, f())