Python pandas.util.testing.add_nans() Examples
The following are 30
code examples of pandas.util.testing.add_nans().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pandas.util.testing
, or try the search function
.
Example #1
Source File: test_groupby.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_panel_groupby(): panel = tm.makePanel() tm.add_nans(panel) grouped = panel.groupby({'ItemA': 0, 'ItemB': 0, 'ItemC': 1}, axis='items') agged = grouped.mean() agged2 = grouped.agg(lambda x: x.mean('items')) tm.assert_panel_equal(agged, agged2) tm.assert_index_equal(agged.items, Index([0, 1])) grouped = panel.groupby(lambda x: x.month, axis='major') agged = grouped.mean() exp = Index(sorted(list(set(panel.major_axis.month)))) tm.assert_index_equal(agged.major_axis, exp) grouped = panel.groupby({'A': 0, 'B': 0, 'C': 1, 'D': 1}, axis='minor') agged = grouped.mean() tm.assert_index_equal(agged.minor_axis, Index([0, 1]))
Example #2
Source File: test_groupby.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_panel_groupby(): with catch_warnings(record=True): panel = tm.makePanel() tm.add_nans(panel) grouped = panel.groupby({'ItemA': 0, 'ItemB': 0, 'ItemC': 1}, axis='items') agged = grouped.mean() agged2 = grouped.agg(lambda x: x.mean('items')) tm.assert_panel_equal(agged, agged2) tm.assert_index_equal(agged.items, Index([0, 1])) grouped = panel.groupby(lambda x: x.month, axis='major') agged = grouped.mean() exp = Index(sorted(list(set(panel.major_axis.month)))) tm.assert_index_equal(agged.major_axis, exp) grouped = panel.groupby({'A': 0, 'B': 0, 'C': 1, 'D': 1}, axis='minor') agged = grouped.mean() tm.assert_index_equal(agged.minor_axis, Index([0, 1]))
Example #3
Source File: test_groupby.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_sparse_friendly(df): sdf = df[['C', 'D']].to_sparse() with catch_warnings(record=True): panel = tm.makePanel() tm.add_nans(panel) def _check_work(gp): gp.mean() gp.agg(np.mean) dict(iter(gp)) # it works! _check_work(sdf.groupby(lambda x: x // 2)) _check_work(sdf['C'].groupby(lambda x: x // 2)) _check_work(sdf.groupby(df['A'])) # do this someday # _check_work(panel.groupby(lambda x: x.month, axis=1))
Example #4
Source File: test_join.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_panel_join_overlap(self): with catch_warnings(record=True): panel = tm.makePanel() tm.add_nans(panel) p1 = panel.loc[['ItemA', 'ItemB', 'ItemC']] p2 = panel.loc[['ItemB', 'ItemC']] # Expected index is # # ItemA, ItemB_p1, ItemC_p1, ItemB_p2, ItemC_p2 joined = p1.join(p2, lsuffix='_p1', rsuffix='_p2') p1_suf = p1.loc[['ItemB', 'ItemC']].add_suffix('_p1') p2_suf = p2.loc[['ItemB', 'ItemC']].add_suffix('_p2') no_overlap = panel.loc[['ItemA']] expected = no_overlap.join(p1_suf.join(p2_suf)) tm.assert_panel_equal(joined, expected)
Example #5
Source File: test_join.py From coffeegrindsize with MIT License | 6 votes |
def test_panel_join_overlap(self): with catch_warnings(record=True): panel = tm.makePanel() tm.add_nans(panel) p1 = panel.loc[['ItemA', 'ItemB', 'ItemC']] p2 = panel.loc[['ItemB', 'ItemC']] # Expected index is # # ItemA, ItemB_p1, ItemC_p1, ItemB_p2, ItemC_p2 joined = p1.join(p2, lsuffix='_p1', rsuffix='_p2') p1_suf = p1.loc[['ItemB', 'ItemC']].add_suffix('_p1') p2_suf = p2.loc[['ItemB', 'ItemC']].add_suffix('_p2') no_overlap = panel.loc[['ItemA']] expected = no_overlap.join(p1_suf.join(p2_suf)) tm.assert_panel_equal(joined, expected)
Example #6
Source File: test_groupby.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def test_panel_groupby(self): with catch_warnings(record=True): self.panel = tm.makePanel() tm.add_nans(self.panel) grouped = self.panel.groupby({'ItemA': 0, 'ItemB': 0, 'ItemC': 1}, axis='items') agged = grouped.mean() agged2 = grouped.agg(lambda x: x.mean('items')) tm.assert_panel_equal(agged, agged2) tm.assert_index_equal(agged.items, Index([0, 1])) grouped = self.panel.groupby(lambda x: x.month, axis='major') agged = grouped.mean() exp = Index(sorted(list(set(self.panel.major_axis.month)))) tm.assert_index_equal(agged.major_axis, exp) grouped = self.panel.groupby({'A': 0, 'B': 0, 'C': 1, 'D': 1}, axis='minor') agged = grouped.mean() tm.assert_index_equal(agged.minor_axis, Index([0, 1]))
Example #7
Source File: test_join.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def test_panel_join_overlap(self): with catch_warnings(record=True): panel = tm.makePanel() tm.add_nans(panel) p1 = panel.loc[['ItemA', 'ItemB', 'ItemC']] p2 = panel.loc[['ItemB', 'ItemC']] # Expected index is # # ItemA, ItemB_p1, ItemC_p1, ItemB_p2, ItemC_p2 joined = p1.join(p2, lsuffix='_p1', rsuffix='_p2') p1_suf = p1.loc[['ItemB', 'ItemC']].add_suffix('_p1') p2_suf = p2.loc[['ItemB', 'ItemC']].add_suffix('_p2') no_overlap = panel.loc[['ItemA']] expected = no_overlap.join(p1_suf.join(p2_suf)) tm.assert_panel_equal(joined, expected)
Example #8
Source File: test_groupby.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_sparse_friendly(df): sdf = df[['C', 'D']].to_sparse() panel = tm.makePanel() tm.add_nans(panel) def _check_work(gp): gp.mean() gp.agg(np.mean) dict(iter(gp)) # it works! _check_work(sdf.groupby(lambda x: x // 2)) _check_work(sdf['C'].groupby(lambda x: x // 2)) _check_work(sdf.groupby(df['A'])) # do this someday # _check_work(panel.groupby(lambda x: x.month, axis=1))
Example #9
Source File: test_join.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_panel_join_overlap(self): with catch_warnings(record=True): panel = tm.makePanel() tm.add_nans(panel) p1 = panel.loc[['ItemA', 'ItemB', 'ItemC']] p2 = panel.loc[['ItemB', 'ItemC']] # Expected index is # # ItemA, ItemB_p1, ItemC_p1, ItemB_p2, ItemC_p2 joined = p1.join(p2, lsuffix='_p1', rsuffix='_p2') p1_suf = p1.loc[['ItemB', 'ItemC']].add_suffix('_p1') p2_suf = p2.loc[['ItemB', 'ItemC']].add_suffix('_p2') no_overlap = panel.loc[['ItemA']] expected = no_overlap.join(p1_suf.join(p2_suf)) tm.assert_panel_equal(joined, expected)
Example #10
Source File: test_join.py From recruit with Apache License 2.0 | 6 votes |
def test_panel_join_overlap(self): with catch_warnings(record=True): panel = tm.makePanel() tm.add_nans(panel) p1 = panel.loc[['ItemA', 'ItemB', 'ItemC']] p2 = panel.loc[['ItemB', 'ItemC']] # Expected index is # # ItemA, ItemB_p1, ItemC_p1, ItemB_p2, ItemC_p2 joined = p1.join(p2, lsuffix='_p1', rsuffix='_p2') p1_suf = p1.loc[['ItemB', 'ItemC']].add_suffix('_p1') p2_suf = p2.loc[['ItemB', 'ItemC']].add_suffix('_p2') no_overlap = panel.loc[['ItemA']] expected = no_overlap.join(p1_suf.join(p2_suf)) tm.assert_panel_equal(joined, expected)
Example #11
Source File: test_groupby.py From recruit with Apache License 2.0 | 6 votes |
def test_sparse_friendly(df): sdf = df[['C', 'D']].to_sparse() panel = tm.makePanel() tm.add_nans(panel) def _check_work(gp): gp.mean() gp.agg(np.mean) dict(iter(gp)) # it works! _check_work(sdf.groupby(lambda x: x // 2)) _check_work(sdf['C'].groupby(lambda x: x // 2)) _check_work(sdf.groupby(df['A'])) # do this someday # _check_work(panel.groupby(lambda x: x.month, axis=1))
Example #12
Source File: test_groupby.py From vnpy_crypto with MIT License | 6 votes |
def test_sparse_friendly(df): sdf = df[['C', 'D']].to_sparse() with catch_warnings(record=True): panel = tm.makePanel() tm.add_nans(panel) def _check_work(gp): gp.mean() gp.agg(np.mean) dict(iter(gp)) # it works! _check_work(sdf.groupby(lambda x: x // 2)) _check_work(sdf['C'].groupby(lambda x: x // 2)) _check_work(sdf.groupby(df['A'])) # do this someday # _check_work(panel.groupby(lambda x: x.month, axis=1))
Example #13
Source File: test_join.py From vnpy_crypto with MIT License | 6 votes |
def test_panel_join_overlap(self): with catch_warnings(record=True): panel = tm.makePanel() tm.add_nans(panel) p1 = panel.loc[['ItemA', 'ItemB', 'ItemC']] p2 = panel.loc[['ItemB', 'ItemC']] # Expected index is # # ItemA, ItemB_p1, ItemC_p1, ItemB_p2, ItemC_p2 joined = p1.join(p2, lsuffix='_p1', rsuffix='_p2') p1_suf = p1.loc[['ItemB', 'ItemC']].add_suffix('_p1') p2_suf = p2.loc[['ItemB', 'ItemC']].add_suffix('_p2') no_overlap = panel.loc[['ItemA']] expected = no_overlap.join(p1_suf.join(p2_suf)) tm.assert_panel_equal(joined, expected)
Example #14
Source File: test_groupby.py From recruit with Apache License 2.0 | 6 votes |
def test_panel_groupby(): panel = tm.makePanel() tm.add_nans(panel) grouped = panel.groupby({'ItemA': 0, 'ItemB': 0, 'ItemC': 1}, axis='items') agged = grouped.mean() agged2 = grouped.agg(lambda x: x.mean('items')) tm.assert_panel_equal(agged, agged2) tm.assert_index_equal(agged.items, Index([0, 1])) grouped = panel.groupby(lambda x: x.month, axis='major') agged = grouped.mean() exp = Index(sorted(list(set(panel.major_axis.month)))) tm.assert_index_equal(agged.major_axis, exp) grouped = panel.groupby({'A': 0, 'B': 0, 'C': 1, 'D': 1}, axis='minor') agged = grouped.mean() tm.assert_index_equal(agged.minor_axis, Index([0, 1]))
Example #15
Source File: test_groupby.py From vnpy_crypto with MIT License | 6 votes |
def test_panel_groupby(): with catch_warnings(record=True): panel = tm.makePanel() tm.add_nans(panel) grouped = panel.groupby({'ItemA': 0, 'ItemB': 0, 'ItemC': 1}, axis='items') agged = grouped.mean() agged2 = grouped.agg(lambda x: x.mean('items')) tm.assert_panel_equal(agged, agged2) tm.assert_index_equal(agged.items, Index([0, 1])) grouped = panel.groupby(lambda x: x.month, axis='major') agged = grouped.mean() exp = Index(sorted(list(set(panel.major_axis.month)))) tm.assert_index_equal(agged.major_axis, exp) grouped = panel.groupby({'A': 0, 'B': 0, 'C': 1, 'D': 1}, axis='minor') agged = grouped.mean() tm.assert_index_equal(agged.minor_axis, Index([0, 1]))
Example #16
Source File: test_join.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_panel_join(self): with catch_warnings(record=True): panel = tm.makePanel() tm.add_nans(panel) p1 = panel.iloc[:2, :10, :3] p2 = panel.iloc[2:, 5:, 2:] # left join result = p1.join(p2) expected = p1.copy() expected['ItemC'] = p2['ItemC'] tm.assert_panel_equal(result, expected) # right join result = p1.join(p2, how='right') expected = p2.copy() expected['ItemA'] = p1['ItemA'] expected['ItemB'] = p1['ItemB'] expected = expected.reindex(items=['ItemA', 'ItemB', 'ItemC']) tm.assert_panel_equal(result, expected) # inner join result = p1.join(p2, how='inner') expected = panel.iloc[:, 5:10, 2:3] tm.assert_panel_equal(result, expected) # outer join result = p1.join(p2, how='outer') expected = p1.reindex(major=panel.major_axis, minor=panel.minor_axis) expected = expected.join(p2.reindex(major=panel.major_axis, minor=panel.minor_axis)) tm.assert_panel_equal(result, expected)
Example #17
Source File: test_join.py From recruit with Apache License 2.0 | 5 votes |
def test_panel_join(self): with catch_warnings(record=True): panel = tm.makePanel() tm.add_nans(panel) p1 = panel.iloc[:2, :10, :3] p2 = panel.iloc[2:, 5:, 2:] # left join result = p1.join(p2) expected = p1.copy() expected['ItemC'] = p2['ItemC'] tm.assert_panel_equal(result, expected) # right join result = p1.join(p2, how='right') expected = p2.copy() expected['ItemA'] = p1['ItemA'] expected['ItemB'] = p1['ItemB'] expected = expected.reindex(items=['ItemA', 'ItemB', 'ItemC']) tm.assert_panel_equal(result, expected) # inner join result = p1.join(p2, how='inner') expected = panel.iloc[:, 5:10, 2:3] tm.assert_panel_equal(result, expected) # outer join result = p1.join(p2, how='outer') expected = p1.reindex(major=panel.major_axis, minor=panel.minor_axis) expected = expected.join(p2.reindex(major=panel.major_axis, minor=panel.minor_axis)) tm.assert_panel_equal(result, expected)
Example #18
Source File: test_join.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_panel_join(self): with catch_warnings(record=True): panel = tm.makePanel() tm.add_nans(panel) p1 = panel.iloc[:2, :10, :3] p2 = panel.iloc[2:, 5:, 2:] # left join result = p1.join(p2) expected = p1.copy() expected['ItemC'] = p2['ItemC'] tm.assert_panel_equal(result, expected) # right join result = p1.join(p2, how='right') expected = p2.copy() expected['ItemA'] = p1['ItemA'] expected['ItemB'] = p1['ItemB'] expected = expected.reindex(items=['ItemA', 'ItemB', 'ItemC']) tm.assert_panel_equal(result, expected) # inner join result = p1.join(p2, how='inner') expected = panel.iloc[:, 5:10, 2:3] tm.assert_panel_equal(result, expected) # outer join result = p1.join(p2, how='outer') expected = p1.reindex(major=panel.major_axis, minor=panel.minor_axis) expected = expected.join(p2.reindex(major=panel.major_axis, minor=panel.minor_axis)) tm.assert_panel_equal(result, expected)
Example #19
Source File: test_panel.py From twitter-stock-recommendation with MIT License | 5 votes |
def make_test_panel(): with catch_warnings(record=True): _panel = tm.makePanel() tm.add_nans(_panel) _panel = _panel.copy() return _panel
Example #20
Source File: test_join.py From coffeegrindsize with MIT License | 5 votes |
def test_panel_join(self): with catch_warnings(record=True): panel = tm.makePanel() tm.add_nans(panel) p1 = panel.iloc[:2, :10, :3] p2 = panel.iloc[2:, 5:, 2:] # left join result = p1.join(p2) expected = p1.copy() expected['ItemC'] = p2['ItemC'] tm.assert_panel_equal(result, expected) # right join result = p1.join(p2, how='right') expected = p2.copy() expected['ItemA'] = p1['ItemA'] expected['ItemB'] = p1['ItemB'] expected = expected.reindex(items=['ItemA', 'ItemB', 'ItemC']) tm.assert_panel_equal(result, expected) # inner join result = p1.join(p2, how='inner') expected = panel.iloc[:, 5:10, 2:3] tm.assert_panel_equal(result, expected) # outer join result = p1.join(p2, how='outer') expected = p1.reindex(major=panel.major_axis, minor=panel.minor_axis) expected = expected.join(p2.reindex(major=panel.major_axis, minor=panel.minor_axis)) tm.assert_panel_equal(result, expected)
Example #21
Source File: test_panel.py From coffeegrindsize with MIT License | 5 votes |
def make_test_panel(): with catch_warnings(record=True): simplefilter("ignore", FutureWarning) _panel = tm.makePanel() tm.add_nans(_panel) _panel = _panel.copy() return _panel
Example #22
Source File: test_missing.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_isna_isnull(self, isna_f): assert not isna_f(1.) assert isna_f(None) assert isna_f(np.NaN) assert float('nan') assert not isna_f(np.inf) assert not isna_f(-np.inf) # series for s in [tm.makeFloatSeries(), tm.makeStringSeries(), tm.makeObjectSeries(), tm.makeTimeSeries(), tm.makePeriodSeries()]: assert isinstance(isna_f(s), Series) # frame for df in [tm.makeTimeDataFrame(), tm.makePeriodFrame(), tm.makeMixedDataFrame()]: result = isna_f(df) expected = df.apply(isna_f) tm.assert_frame_equal(result, expected) # panel with catch_warnings(record=True): for p in [tm.makePanel(), tm.makePeriodPanel(), tm.add_nans(tm.makePanel())]: result = isna_f(p) expected = p.apply(isna_f) tm.assert_panel_equal(result, expected) # panel 4d with catch_warnings(record=True): for p in [tm.makePanel4D(), tm.add_nans_panel4d(tm.makePanel4D())]: result = isna_f(p) expected = p.apply(isna_f) tm.assert_panel4d_equal(result, expected)
Example #23
Source File: test_panel.py From vnpy_crypto with MIT License | 5 votes |
def make_test_panel(): with catch_warnings(record=True): _panel = tm.makePanel() tm.add_nans(_panel) _panel = _panel.copy() return _panel
Example #24
Source File: test_join.py From vnpy_crypto with MIT License | 5 votes |
def test_panel_join(self): with catch_warnings(record=True): panel = tm.makePanel() tm.add_nans(panel) p1 = panel.iloc[:2, :10, :3] p2 = panel.iloc[2:, 5:, 2:] # left join result = p1.join(p2) expected = p1.copy() expected['ItemC'] = p2['ItemC'] tm.assert_panel_equal(result, expected) # right join result = p1.join(p2, how='right') expected = p2.copy() expected['ItemA'] = p1['ItemA'] expected['ItemB'] = p1['ItemB'] expected = expected.reindex(items=['ItemA', 'ItemB', 'ItemC']) tm.assert_panel_equal(result, expected) # inner join result = p1.join(p2, how='inner') expected = panel.iloc[:, 5:10, 2:3] tm.assert_panel_equal(result, expected) # outer join result = p1.join(p2, how='outer') expected = p1.reindex(major=panel.major_axis, minor=panel.minor_axis) expected = expected.join(p2.reindex(major=panel.major_axis, minor=panel.minor_axis)) tm.assert_panel_equal(result, expected)
Example #25
Source File: test_panel4d.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def setup_method(self, method): with catch_warnings(record=True): self.panel4d = tm.makePanel4D(nper=8) add_nans(self.panel4d)
Example #26
Source File: test_panel4d.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def add_nans(panel4d): for l, label in enumerate(panel4d.labels): panel = panel4d[label] tm.add_nans(panel)
Example #27
Source File: test_panel.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def make_test_panel(): with catch_warnings(record=True): _panel = tm.makePanel() tm.add_nans(_panel) _panel = _panel.copy() return _panel
Example #28
Source File: test_panel.py From recruit with Apache License 2.0 | 5 votes |
def make_test_panel(): with catch_warnings(record=True): simplefilter("ignore", FutureWarning) _panel = tm.makePanel() tm.add_nans(_panel) _panel = _panel.copy() return _panel
Example #29
Source File: test_join.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_panel_join(self): with catch_warnings(record=True): panel = tm.makePanel() tm.add_nans(panel) p1 = panel.iloc[:2, :10, :3] p2 = panel.iloc[2:, 5:, 2:] # left join result = p1.join(p2) expected = p1.copy() expected['ItemC'] = p2['ItemC'] tm.assert_panel_equal(result, expected) # right join result = p1.join(p2, how='right') expected = p2.copy() expected['ItemA'] = p1['ItemA'] expected['ItemB'] = p1['ItemB'] expected = expected.reindex(items=['ItemA', 'ItemB', 'ItemC']) tm.assert_panel_equal(result, expected) # inner join result = p1.join(p2, how='inner') expected = panel.iloc[:, 5:10, 2:3] tm.assert_panel_equal(result, expected) # outer join result = p1.join(p2, how='outer') expected = p1.reindex(major=panel.major_axis, minor=panel.minor_axis) expected = expected.join(p2.reindex(major=panel.major_axis, minor=panel.minor_axis)) tm.assert_panel_equal(result, expected)
Example #30
Source File: test_panel.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def make_test_panel(): with catch_warnings(record=True): simplefilter("ignore", FutureWarning) _panel = tm.makePanel() tm.add_nans(_panel) _panel = _panel.copy() return _panel