def test_transform_dom_fmt_list(self): df = pd.DataFrame( {"date_column": ["2016-05-28", "2016-06-27", "2016-07-26"]}) trainable = Map(columns=[day_of_month(it.date_column, "%Y-%m-%d")]) trained = trainable.fit(df) transformed_df = trained.transform(df) self.assertEqual(transformed_df["date_column"][0], 28) self.assertEqual(transformed_df["date_column"][1], 27) self.assertEqual(transformed_df["date_column"][2], 26)
def test_transform_dom_fmt_list(self): df = pd.DataFrame( {"date_column": ["28/05/2016", "27/06/2016", "26/07/2016"]}) sdf = self.sqlCtx.createDataFrame(df) trainable = Map(columns=[day_of_month(it.date_column, "d/M/y")]) trained = trainable.fit(sdf) transformed_df = trained.transform(sdf) self.assertEqual(transformed_df.collect()[0]["date_column"], 28) self.assertEqual(transformed_df.collect()[1]["date_column"], 27) self.assertEqual(transformed_df.collect()[2]["date_column"], 26)
def test_transform_dom_list(self): df = pd.DataFrame( {"date_column": ["2016-05-28", "2016-06-27", "2016-07-26"]}) sdf = self.sqlCtx.createDataFrame(df) trainable = Map(columns=[day_of_month(it.date_column)]) trained = trainable.fit(sdf) transformed_df = trained.transform(sdf) self.assertEqual(transformed_df.collect()[0]["date_column"], 28) self.assertEqual(transformed_df.collect()[1]["date_column"], 27) self.assertEqual(transformed_df.collect()[2]["date_column"], 26)
def test_transform_dom_fmt_map(self): df = pd.DataFrame( {"date_column": ["2016-05-28", "2016-06-27", "2016-07-26"]}) sdf = self.sqlCtx.createDataFrame(df) trainable = Map(columns={"dom": day_of_month(it.date_column, "y-M-d")}) trained = trainable.fit(sdf) transformed_df = trained.transform(sdf) self.assertEqual((transformed_df.count(), len(transformed_df.columns)), (3, 1)) self.assertEqual(transformed_df.collect()[0]["dom"], 28) self.assertEqual(transformed_df.collect()[1]["dom"], 27) self.assertEqual(transformed_df.collect()[2]["dom"], 26)