Ejemplo n.º 1
0
    def test_gt_lt(self):
        df_result = df5 > 3
        df_answer = pdc.DataFrame({'a': a5 > 3, 'b': b5 > 3})
        assert_df_equals(df_result, df_answer)

        df_result = df5 < 2
        df_answer = pdc.DataFrame({'a': a5 < 2, 'b': b5 < 2})
        assert_df_equals(df_result, df_answer)
Ejemplo n.º 2
0
    def test_ge_le(self):
        df_result = df5 >= 3
        df_answer = pdc.DataFrame({'a': a5 >= 3, 'b': b5 >= 3})
        assert_df_equals(df_result, df_answer)

        df_result = df5 < 2
        df_answer = pdc.DataFrame({'a': a5 <= 2, 'b': b5 <= 2})
        assert_df_equals(df_result, df_answer)
Ejemplo n.º 3
0
    def test_sub(self):
        df_result = df5 - 3
        df_answer = pdc.DataFrame({'a': a5 - 3, 'b': b5 - 3})
        assert_df_equals(df_result, df_answer)

        df_result = 3 - df5
        df_answer = pdc.DataFrame({'a': 3 - a5, 'b': 3 - b5})
        assert_df_equals(df_result, df_answer)
Ejemplo n.º 4
0
    def test_eq_ne(self):
        df_result = df5 == 3
        df_answer = pdc.DataFrame({'a': a5 == 3, 'b': b5 == 3})
        assert_df_equals(df_result, df_answer)

        df_result = df5 != 2
        df_answer = pdc.DataFrame({'a': a5 != 2, 'b': b5 != 2})
        assert_df_equals(df_result, df_answer)
Ejemplo n.º 5
0
    def test_pow(self):
        df_result = df5**3
        df_answer = pdc.DataFrame({'a': a5**3, 'b': b5**3})
        assert_df_equals(df_result, df_answer)

        df_result = 2**df5
        df_answer = pdc.DataFrame({'a': 2**a5, 'b': 2**b5})
        assert_df_equals(df_result, df_answer)
Ejemplo n.º 6
0
    def test_floordiv(self):
        df_result = df5 // 3
        df_answer = pdc.DataFrame({'a': a5 // 3, 'b': b5 // 3})
        assert_df_equals(df_result, df_answer)

        df_result = 3 // df5
        df_answer = pdc.DataFrame({'a': 3 // a5, 'b': 3 // b5})
        assert_df_equals(df_result, df_answer)
Ejemplo n.º 7
0
    def test_input_types(self):  ## test _check_input_types
        with pytest.raises(TypeError):
            pdc.DataFrame([1, 2, 3])

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

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

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

        # correct construction. no error
        pdc.DataFrame({'a': np.array([1]), 'b': np.array([1])})
Ejemplo n.º 8
0
 def test_std(self):
     df_result = df1.std()
     df_answer = pdc.DataFrame({
         'b': np.array([b1.std()]),
         'c': np.array([np.nan])
     })
     assert_df_equals(df_result, df_answer)
Ejemplo n.º 9
0
 def test_median(self):
     df_result = df1.median()
     df_answer = pdc.DataFrame({
         'b': np.array([8]),
         'c': np.array([np.nan])
     })
     assert_df_equals(df_result, df_answer)
Ejemplo n.º 10
0
 def test_clip(self):
     df_result = df42.clip(0, 4)
     df_answer = pdc.DataFrame({
         'a': np.array([0, 4, 3]),
         'b': np.array([3.4, 4, 0])
     })
     assert_df_equals(df_result, df_answer)
Ejemplo n.º 11
0
    def test_mul(self):
        df_result = df5 * 3
        df_answer = pdc.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)
Ejemplo n.º 12
0
    def test_add(self):
        df_result = df5 + 3
        df_answer = pdc.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)
Ejemplo n.º 13
0
 def test_diff(self):
     df_result = df42.diff(1)
     df_answer = pdc.DataFrame({
         'a': np.array([np.nan, 16, -2]),
         'b': np.array([np.nan, 1.7, -11.1])
     })
     assert_df_equals(df_result, df_answer)
Ejemplo n.º 14
0
 def test_cumsum(self):
     df_result = df42.cumsum()
     df_answer = pdc.DataFrame({
         'a': np.array([-11, -6, -3]),
         'b': np.array([3.4, 8.5, 2.5])
     })
     assert_df_equals(df_result, df_answer)
Ejemplo n.º 15
0
 def test_round(self):
     df_result = df42.round(0)
     df_answer = pdc.DataFrame({
         'a': np.array([-11, 5, 3]),
         'b': np.array([3, 5, -6])
     })
     assert_df_equals(df_result, df_answer)
Ejemplo n.º 16
0
 def test_cummax(self):
     df_result = df42.cummax()
     df_answer = pdc.DataFrame({
         'a': np.array([-11, 5, 5]),
         'b': np.array([3.4, 5.1, 5.1])
     })
     assert_df_equals(df_result, df_answer)
Ejemplo n.º 17
0
 def test_cummin(self):
     df_result = df42.cummin()
     df_answer = pdc.DataFrame({
         'a': np.array([-11, -11, -11]),
         'b': np.array([3.4, 3.4, -6])
     })
     assert_df_equals(df_result, df_answer)
Ejemplo n.º 18
0
 def test_nunique(self):
     df_result = df4.nunique()
     df_answer = pdc.DataFrame({
         'a': np.array([2]),
         'b': np.array([2]),
         'c': np.array([2])
     })
     assert_df_equals(df_result, df_answer)
Ejemplo n.º 19
0
 def test_sum(self):
     df_result = df1.sum()
     df_answer = pdc.DataFrame({
         'a': np.array(['abc'], dtype='O'),
         'b': np.array([24]),
         'c': np.array([np.nan])
     })
     assert_df_equals(df_result, df_answer)
Ejemplo n.º 20
0
 def test_any(self):
     df_result = df2.any()
     df_answer = pdc.DataFrame({
         'a': np.array([True]),
         'b': np.array([True]),
         'c': np.array([True])
     })
     assert_df_equals(df_result, df_answer)
Ejemplo n.º 21
0
 def test_argmin(self):
     df_result = df1.argmin()
     df_answer = pdc.DataFrame({
         'a': np.array([0]),
         'b': np.array([1]),
         'c': np.array([1])
     })
     assert_df_equals(df_result, df_answer)
Ejemplo n.º 22
0
 def test_isna(self):
     df_result = df3.isna()
     df_answer = pdc.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)
Ejemplo n.º 23
0
 def test_count(self):
     df_result = df3.count()
     df_answer = pdc.DataFrame({
         'a': np.array([2]),
         'b': np.array([3]),
         'c': np.array([2])
     })
     assert_df_equals(df_result, df_answer)
Ejemplo n.º 24
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 = pdc.DataFrame({'Column Name': cols, 'Data Type': dtypes})
        assert_df_equals(df_result, df_answer)
Ejemplo n.º 25
0
    def test_col_slice(self):
        df_answer = pdc.DataFrame({'a': a, 'b': b, 'c': c})
        assert_df_equals(df[:, :3], df_answer)

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

        df_answer = pdc.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()]
Ejemplo n.º 26
0
 def test_pct_change(self):
     df_result = df42.pct_change(1)
     df_answer = pdc.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)
Ejemplo n.º 27
0
    def test_simple_boolean(self):
        bool_arr = np.array([True, False, False])
        df_bool = pdc.DataFrame({'col': bool_arr})
        df_result = df[df_bool]
        df_answer = pdc.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 = pdc.DataFrame({'col': bool_arr, 'col2': bool_arr})
            df[df_bool]

        with pytest.raises(TypeError):
            df_bool = pdc.DataFrame({'col': np.array[1, 2, 3]})
Ejemplo n.º 28
0
    def test_list_columns(self):
        df_answer = pdc.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 = pdc.DataFrame({'a': a[[2]], 'e': e[[2]]})
        assert_df_equals(df_result, df_answer)

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

        df1 = pdc.DataFrame({
            'a': np.array([True, False, True]),
            'b': np.array([1, 3, 5])
        })
        df_answer = pdc.DataFrame({'c': c[[0, 2]], 'e': e[[0, 2]]})
        assert_df_equals(df[df1['a'], ['c', 'e']], df_answer)
Ejemplo n.º 29
0
 def test_pivot_table_both(self):
     df_result = df8.pivot_table(rows='a',
                                 columns='b',
                                 values='c',
                                 aggfunc='sum')
     df_answer = pdc.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)
Ejemplo n.º 30
0
    def test_sample(self):
        df_result = df7.sample(2, seed=1)
        df_answer = pdc.DataFrame({
            'a': np.array(['a', 'a'], dtype=object),
            'b': np.array([2., 5.1])
        })
        assert_df_equals(df_result, df_answer)

        df_result = df7.sample(frac=.7, seed=1)
        df_answer = pdc.DataFrame({
            'a': np.array(['a', 'a', 'b'], dtype=object),
            'b': np.array([2., 5.1, 6.])
        })
        assert_df_equals(df_result, df_answer)

        with pytest.raises(TypeError):
            df7.sample(2.5)

        with pytest.raises(ValueError):
            df7.sample(frac=-2)