|
5 | 5 | import nose
|
6 | 6 |
|
7 | 7 | import numpy as np
|
8 |
| - |
| 8 | +import warnings |
9 | 9 | from pandas import Series, DataFrame, Index, isnull, notnull, pivot, MultiIndex
|
10 | 10 | from pandas.core.datetools import bday
|
11 | 11 | from pandas.core.panel import Panel
|
@@ -1556,6 +1556,36 @@ def test_to_frame_multi_drop_level(self):
|
1556 | 1556 | expected = DataFrame({'i1': [1., 2], 'i2': [1., 2]}, index=exp_idx)
|
1557 | 1557 | assert_frame_equal(result, expected)
|
1558 | 1558 |
|
| 1559 | + def test_to_frame_na_drop_warnings(self): |
| 1560 | + def create_a_panel_with_na_vals(filter_observations=True): |
| 1561 | + df1 = DataFrame(np.random.randn(2, 3), columns=['A', 'B', 'C'], |
| 1562 | + index=['foo', 'bar']) |
| 1563 | + df2 = DataFrame(np.random.randn(2, 3), columns=['A', 'B', 'C'], |
| 1564 | + index=['foo', 'bar']) |
| 1565 | + df2.loc['foo', 'B'] = np.nan |
| 1566 | + dict_with_dropped_vals = {'df1': df1, 'df2': df2} |
| 1567 | + Panel(dict_with_dropped_vals).\ |
| 1568 | + to_frame(filter_observations=filter_observations) |
| 1569 | + |
| 1570 | + def create_a_panel_without_na_vals(filter_observations=True): |
| 1571 | + df1 = DataFrame(np.random.randn(2, 3), columns=['A', 'B', 'C'], |
| 1572 | + index=['foo', 'bar']) |
| 1573 | + df2 = DataFrame(np.random.randn(2, 3), columns=['A', 'B', 'C'], |
| 1574 | + index=['foo', 'bar']) |
| 1575 | + dict_with_dropped_vals = {'df1': df1, 'df2': df2} |
| 1576 | + Panel(dict_with_dropped_vals).\ |
| 1577 | + to_frame(filter_observations=filter_observations) |
| 1578 | + with warnings.catch_warnings(record=True) as w: |
| 1579 | + warnings.simplefilter("always") |
| 1580 | + create_a_panel_with_na_vals() |
| 1581 | + create_a_panel_with_na_vals(False) |
| 1582 | + create_a_panel_without_na_vals() |
| 1583 | + create_a_panel_without_na_vals(False) |
| 1584 | + self.assertEqual(len(w), 1) |
| 1585 | + self.assertTrue(issubclass(w[0].category, RuntimeWarning)) |
| 1586 | + self.assertEqual(str(w[0].message), |
| 1587 | + "NaN values found, empty values will be dropped") |
| 1588 | + |
1559 | 1589 | def test_to_panel_na_handling(self):
|
1560 | 1590 | df = DataFrame(np.random.randint(0, 10, size=20).reshape((10, 2)),
|
1561 | 1591 | index=[[0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
|
|
0 commit comments