コード例 #1
0
    def test_sub(self):
        df_result = df5 - 3
        df_answer = bd.DataFrame({'a': a5 - 3, 'b': b5 - 3})
        assert_df_equals(df_result, df_answer)

        df_result = 3 - df5
        df_answer = bd.DataFrame({'a': 3 - a5, 'b': 3 - b5})
        assert_df_equals(df_result, df_answer)
コード例 #2
0
    def test_ge_le(self):
        df_result = df5 >= 3
        df_answer = bd.DataFrame({'a': a5 >= 3, 'b': b5 >= 3})
        assert_df_equals(df_result, df_answer)

        df_result = df5 < 2
        df_answer = bd.DataFrame({'a': a5 <= 2, 'b': b5 <= 2})
        assert_df_equals(df_result, df_answer)
コード例 #3
0
    def test_gt_lt(self):
        df_result = df5 > 3
        df_answer = bd.DataFrame({'a': a5 > 3, 'b': b5 > 3})
        assert_df_equals(df_result, df_answer)

        df_result = df5 < 2
        df_answer = bd.DataFrame({'a': a5 < 2, 'b': b5 < 2})
        assert_df_equals(df_result, df_answer)
コード例 #4
0
    def test_eq_ne(self):
        df_result = df5 == 3
        df_answer = bd.DataFrame({'a': a5 == 3, 'b': b5 == 3})
        assert_df_equals(df_result, df_answer)

        df_result = df5 != 2
        df_answer = bd.DataFrame({'a': a5 != 2, 'b': b5 != 2})
        assert_df_equals(df_result, df_answer)
コード例 #5
0
    def test_pow(self):
        df_result = df5**3
        df_answer = bd.DataFrame({'a': a5**3, 'b': b5**3})
        assert_df_equals(df_result, df_answer)

        df_result = 2**df5
        df_answer = bd.DataFrame({'a': 2**a5, 'b': 2**b5})
        assert_df_equals(df_result, df_answer)
コード例 #6
0
    def test_floordiv(self):
        df_result = df5 // 3
        df_answer = bd.DataFrame({'a': a5 // 3, 'b': b5 // 3})
        assert_df_equals(df_result, df_answer)

        df_result = 3 // df5
        df_answer = bd.DataFrame({'a': 3 // a5, 'b': 3 // b5})
        assert_df_equals(df_result, df_answer)
コード例 #7
0
    def test_input_types(self):
        with pytest.raises(TypeError):
            bd.DataFrame([1, 2, 3])

        with pytest.raises(TypeError):
            bd.DataFrame({1: 5, 'b': 10})

        with pytest.raises(TypeError):
            bd.DataFrame({'a': np.array([1]), 'b': 10})

        with pytest.raises(ValueError):
            bd.DataFrame({'a': np.array([1]), 'b': np.array([[1]])})

        # correct construction. no error
        bd.DataFrame({'a': np.array([1]), 'b': np.array([1])})
コード例 #8
0
 def test_std(self):
     df_result = df1.std()
     df_answer = bd.DataFrame({
         'b': np.array([b1.std()]),
         'c': np.array([np.nan])
     })
     assert_df_equals(df_result, df_answer)
コード例 #9
0
 def test_mean(self):
     df_result = df1.mean()
     df_answer = bd.DataFrame({
         'b': np.array([8.]),
         'c': np.array([np.nan])
     })
     assert_df_equals(df_result, df_answer)
コード例 #10
0
 def test_cumsum(self):
     df_result = df42.cumsum()
     df_answer = bd.DataFrame({
         'a': np.array([-11, -6, -3]),
         'b': np.array([3.4, 8.5, 2.5])
     })
     assert_df_equals(df_result, df_answer)
コード例 #11
0
 def test_round(self):
     df_result = df42.round(0)
     df_answer = bd.DataFrame({
         'a': np.array([-11, 5, 3]),
         'b': np.array([3, 5, -6])
     })
     assert_df_equals(df_result, df_answer)
コード例 #12
0
    def test_mul(self):
        df_result = df5 * 3
        df_answer = bd.DataFrame({'a': a5 * 3, 'b': b5 * 3})
        assert_df_equals(df_result, df_answer)

        df_result = 3 * df5
        assert_df_equals(df_result, df_answer)
コード例 #13
0
    def test_add(self):
        df_result = df5 + 3
        df_answer = bd.DataFrame({'a': a5 + 3, 'b': b5 + 3})
        assert_df_equals(df_result, df_answer)

        df_result = 3 + df5
        assert_df_equals(df_result, df_answer)
コード例 #14
0
 def test_diff(self):
     df_result = df42.diff(1)
     df_answer = bd.DataFrame({
         'a': np.array([np.nan, 16, -2]),
         'b': np.array([np.nan, 1.7, -11.1])
     })
     assert_df_equals(df_result, df_answer)
コード例 #15
0
 def test_cummax(self):
     df_result = df42.cummax()
     df_answer = bd.DataFrame({
         'a': np.array([-11, 5, 5]),
         'b': np.array([3.4, 5.1, 5.1])
     })
     assert_df_equals(df_result, df_answer)
コード例 #16
0
 def test_clip(self):
     df_result = df42.clip(0, 4)
     df_answer = bd.DataFrame({
         'a': np.array([0, 4, 3]),
         'b': np.array([3.4, 4, 0])
     })
     assert_df_equals(df_result, df_answer)
コード例 #17
0
 def test_cummin(self):
     df_result = df42.cummin()
     df_answer = bd.DataFrame({
         'a': np.array([-11, -11, -11]),
         'b': np.array([3.4, 3.4, -6])
     })
     assert_df_equals(df_result, df_answer)
コード例 #18
0
 def test_nunique(self):
     df_result = df4.nunique()
     df_answer = bd.DataFrame({
         'a': np.array([2]),
         'b': np.array([2]),
         'c': np.array([2])
     })
     assert_df_equals(df_result, df_answer)
コード例 #19
0
 def test_max(self):
     df_result = df1.max()
     df_answer = bd.DataFrame({
         'a': np.array(['c'], dtype='O'),
         'b': np.array([11]),
         'c': np.array([np.nan])
     })
     assert_df_equals(df_result, df_answer)
コード例 #20
0
 def test_sum(self):
     df_result = df1.sum()
     df_answer = bd.DataFrame({
         'a': np.array(['abc'], dtype='O'),
         'b': np.array([24]),
         'c': np.array([np.nan])
     })
     assert_df_equals(df_result, df_answer)
コード例 #21
0
 def test_any(self):
     df_result = df2.any()
     df_answer = bd.DataFrame({
         'a': np.array([True]),
         'b': np.array([True]),
         'c': np.array([True])
     })
     assert_df_equals(df_result, df_answer)
コード例 #22
0
 def test_argmin(self):
     df_result = df1.argmin()
     df_answer = bd.DataFrame({
         'a': np.array([0]),
         'b': np.array([1]),
         'c': np.array([1])
     })
     assert_df_equals(df_result, df_answer)
コード例 #23
0
 def test_count(self):
     df_result = df3.count()
     df_answer = bd.DataFrame({
         'a': np.array([2]),
         'b': np.array([3]),
         'c': np.array([2])
     })
     assert_df_equals(df_result, df_answer)
コード例 #24
0
 def test_isna(self):
     df_result = df3.isna()
     df_answer = bd.DataFrame({
         'a': np.array([False, True, False]),
         'b': np.array([False, False, False]),
         'c': np.array([False, True, False])
     })
     assert_df_equals(df_result, df_answer)
コード例 #25
0
    def test_dtypes(self):
        cols = np.array(['a', 'b', 'c', 'd', 'e'], dtype='O')
        dtypes = np.array(['string', 'string', 'float', 'bool', 'int'],
                          dtype='O')

        df_result = df.dtypes
        df_answer = bd.DataFrame({'Column Name': cols, 'Data Type': dtypes})
        assert_df_equals(df_result, df_answer)
コード例 #26
0
    def test_col_slice(self):
        df_answer = bd.DataFrame({'a': a, 'b': b, 'c': c})
        assert_df_equals(df[:, :3], df_answer)

        df_answer = bd.DataFrame({'a': a[::2], 'b': b[::2], 'c': c[::2]})
        assert_df_equals(df[::2, :3], df_answer)

        df_answer = bd.DataFrame({
            'a': a[::2],
            'b': b[::2],
            'c': c[::2],
            'd': d[::2],
            'e': e[::2]
        })
        assert_df_equals(df[::2, :], df_answer)

        with pytest.raises(TypeError):
            df[:, set()]
コード例 #27
0
 def test_pct_change(self):
     df_result = df42.pct_change(1)
     df_answer = bd.DataFrame({
         'a':
         np.array([np.nan, 16 / -11, -2 / 5]),
         'b':
         np.array([np.nan, 1.7 / 3.4, -11.1 / 5.1])
     })
     assert_df_equals(df_result, df_answer)
コード例 #28
0
    def test_simple_boolean(self):
        bool_arr = np.array([True, False, False])
        df_bool = bd.DataFrame({'col': bool_arr})
        df_result = df[df_bool]
        df_answer = bd.DataFrame({
            'a': a[bool_arr],
            'b': b[bool_arr],
            'c': c[bool_arr],
            'd': d[bool_arr],
            'e': e[bool_arr]
        })
        assert_df_equals(df_result, df_answer)

        with pytest.raises(ValueError):
            df_bool = bd.DataFrame({'col': bool_arr, 'col2': bool_arr})
            df[df_bool]

        with pytest.raises(TypeError):
            df_bool = bd.DataFrame({'col': np.array[1, 2, 3]})
コード例 #29
0
    def test_list_columns(self):
        df_answer = bd.DataFrame({'c': c, 'e': e})
        assert_df_equals(df[:, [2, 4]], df_answer)
        assert_df_equals(df[:, [2, 'e']], df_answer)
        assert_df_equals(df[:, ['c', 'e']], df_answer)

        df_result = df[2, ['a', 'e']]
        df_answer = bd.DataFrame({'a': a[[2]], 'e': e[[2]]})
        assert_df_equals(df_result, df_answer)

        df_answer = bd.DataFrame({'c': c[[1, 2]], 'e': e[[1, 2]]})
        assert_df_equals(df[[1, 2], ['c', 'e']], df_answer)

        df1 = bd.DataFrame({
            'a': np.array([True, False, True]),
            'b': np.array([1, 3, 5])
        })
        df_answer = bd.DataFrame({'c': c[[0, 2]], 'e': e[[0, 2]]})
        assert_df_equals(df[df1['a'], ['c', 'e']], df_answer)
コード例 #30
0
 def test_pivot_table_both(self):
     df_result = df8.pivot_table(rows='a',
                                 columns='b',
                                 values='c',
                                 aggfunc='sum')
     df_answer = bd.DataFrame({
         'a': np.array(['a', 'b'], dtype=object),
         'A': np.array([9., 8.]),
         'B': np.array([13., 6.])
     })
     assert_df_equals(df_result, df_answer)