def test_format(self): series = pd.Series( [dt(1999, 2, 3, 4, 5, 6, 7), np.nan, dt(2000, 3, 4, 5, 6, 7, 8)] ) column_type = ColumnType.DATETIME() result = column_type.format_series(series) assert_series_equal( result, pd.Series( ["1999-02-03T04:05:06.000007Z", np.nan, "2000-03-04T05:06:07.000008Z"] ), )
def test_ctor_infer_columns(self): result = ProcessResult( pd.DataFrame( { "A": [1, 2], "B": ["x", "y"], "C": [np.nan, dt(2019, 3, 3, 4, 5, 6, 7)], } ) ) self.assertEqual( result.columns, [ Column("A", ColumnType.NUMBER()), Column("B", ColumnType.TEXT()), Column("C", ColumnType.DATETIME()), ], )
def test_arrow_datetime_column(self): dataframe, columns = arrow_table_to_dataframe( arrow_table( { "A": pyarrow.array( [dt.fromisoformat("2019-09-17T21:21:00.123456"), None], type=pyarrow.timestamp(unit="ns", tz=None), ) }, [atypes.Column("A", atypes.ColumnType.Datetime())], ) ) assert_frame_equal( dataframe, pd.DataFrame( {"A": ["2019-09-17T21:21:00.123456Z", None]}, dtype="datetime64[ns]" ), ) self.assertEqual(columns, [Column("A", ColumnType.DATETIME())])
def test_columns(self): df = pd.DataFrame( { "A": [1], # number "B": ["foo"], # str "C": dt(2018, 8, 20), # datetime64 } ) df["D"] = pd.Series(["cat"], dtype="category") result = ProcessResult(df) self.assertEqual(result.column_names, ["A", "B", "C", "D"]) self.assertEqual( result.columns, [ Column("A", ColumnType.NUMBER()), Column("B", ColumnType.TEXT()), Column("C", ColumnType.DATETIME()), Column("D", ColumnType.TEXT()), ], )
def test_to_arrow(self): self.assertEqual(ColumnType.DATETIME().to_arrow(), atypes.ColumnType.Datetime())
def test_from_arrow(self): self.assertEqual( ColumnType.from_arrow(atypes.ColumnType.Datetime()), ColumnType.DATETIME() )