test_panel.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- coding: utf-8 -*-
  2. # pylint: disable-msg=E1101,W0612
  3. from warnings import catch_warnings, simplefilter
  4. import pandas.util._test_decorators as td
  5. from pandas import Panel
  6. import pandas.util.testing as tm
  7. from pandas.util.testing import assert_almost_equal, assert_panel_equal
  8. from .test_generic import Generic
  9. class TestPanel(Generic):
  10. _typ = Panel
  11. _comparator = lambda self, x, y: assert_panel_equal(x, y, by_blocks=True)
  12. @td.skip_if_no('xarray', min_version='0.7.0')
  13. def test_to_xarray(self):
  14. from xarray import DataArray
  15. with catch_warnings(record=True):
  16. simplefilter("ignore", FutureWarning)
  17. p = tm.makePanel()
  18. result = p.to_xarray()
  19. assert isinstance(result, DataArray)
  20. assert len(result.coords) == 3
  21. assert_almost_equal(list(result.coords.keys()),
  22. ['items', 'major_axis', 'minor_axis'])
  23. assert len(result.dims) == 3
  24. # idempotency
  25. assert_panel_equal(result.to_pandas(), p)
  26. # run all the tests, but wrap each in a warning catcher
  27. for t in ['test_rename', 'test_get_numeric_data',
  28. 'test_get_default', 'test_nonzero',
  29. 'test_downcast', 'test_constructor_compound_dtypes',
  30. 'test_head_tail',
  31. 'test_size_compat', 'test_split_compat',
  32. 'test_unexpected_keyword',
  33. 'test_stat_unexpected_keyword', 'test_api_compat',
  34. 'test_stat_non_defaults_args',
  35. 'test_truncate_out_of_bounds',
  36. 'test_metadata_propagation', 'test_copy_and_deepcopy',
  37. 'test_pct_change', 'test_sample']:
  38. def f():
  39. def tester(self):
  40. f = getattr(super(TestPanel, self), t)
  41. with catch_warnings(record=True):
  42. simplefilter("ignore", FutureWarning)
  43. f()
  44. return tester
  45. setattr(TestPanel, t, f())