def test_pivot_longer_matches_error(self): """ Test if selection helper retrieves no matches """ with self.assertRaises(ValueError): stang = data.df_stang_wide long = gr.tran_pivot_longer( stang, columns = gr.matches("0123"), names_to="var", values_to="val" )
def test_pivot_longer_matches(self): """ Test if pivot_longer is compatible with gr.matches as columns input """ stang = data.df_stang_wide long = gr.tran_pivot_longer( stang, columns = gr.matches("\\d+"), names_to="var", values_to="val" ) expected = gr.tran_pivot_longer( stang, columns=["E_00","mu_00","E_45","mu_45","E_90","mu_90"], names_to="var", values_to="val" ) assert_frame_equal(long, expected)
def test_pivot_longer_select(self): """ Test if pivot_longer is compatible with gr.tran_select or any input of a DataFrame instead as 'columns' argument """ stang = data.df_stang_wide long = gr.tran_pivot_longer( stang, columns=(gr.tran_select(stang,gr.matches("\\d+"))), names_to="var", values_to="val" ) expected = gr.tran_pivot_longer( stang, columns=["E_00","mu_00","E_45","mu_45","E_90","mu_90"], names_to="var", values_to="val" ) assert_frame_equal(long, expected)
def test_drop_matches(self): df = data.df_diamonds[["depth", "table", "x", "y", "z"]] assert df.equals( data.df_diamonds >> gr.tf_drop(gr.matches("^c[auol]|p.i")))
def test_select_matches(self): df = data.df_diamonds[["carat", "cut", "color", "clarity", "price"]] assert df.equals( data.df_diamonds >> gr.tf_select(gr.matches("^c[auol]|pri")))