def test_flights_datetime_metrics_agg(self, agg): ed_timestamps = self.ed_flights()["timestamp"] expected_values = { "min": pd.Timestamp("2018-01-01 00:00:00"), "mean": pd.Timestamp("2018-01-21 19:20:45.564438232"), "max": pd.Timestamp("2018-02-11 23:50:12"), } ed_metric = getattr(ed_timestamps, agg)() assert_almost_equal(ed_metric, expected_values[agg])
def test_flights_datetime_metrics_agg_func(self, agg): ed_timestamps = self.ed_flights()[["timestamp"]] expected_values = { "min": pd.Timestamp("2018-01-01 00:00:00"), "mean": pd.Timestamp("2018-01-21 19:20:45.564438232"), "max": pd.Timestamp("2018-02-11 23:50:12"), } ed_metric = getattr(ed_timestamps, agg)(numeric_only=False) assert ed_metric.dtype == np.dtype("datetime64[ns]") assert_almost_equal(ed_metric[0], expected_values[agg])
def test_flights_datetime_metrics_single_agg(self, agg): ed_timestamps = self.ed_flights()[["timestamp"]] expected_values = { "min": pd.Timestamp("2018-01-01 00:00:00"), "mean": pd.Timestamp("2018-01-21 19:20:45.564438232"), "max": pd.Timestamp("2018-02-11 23:50:12"), "nunique": 12236, } ed_metric = ed_timestamps.agg([agg]) if agg == "nunique": # df with timestamp column should return int64 assert ed_metric.dtypes["timestamp"] == np.int64 else: # df with timestamp column should return datetime64[ns] assert ed_metric.dtypes["timestamp"] == np.dtype("datetime64[ns]") assert_almost_equal(ed_metric["timestamp"][0], expected_values[agg])
def test_flights_datetime_metrics_agg(self): ed_timestamps = self.ed_flights()[["timestamp"]] expected_values = { "max": pd.Timestamp("2018-02-11 23:50:12"), "min": pd.Timestamp("2018-01-01 00:00:00"), "mean": pd.Timestamp("2018-01-21 19:20:45.564438232"), "sum": pd.NaT, "mad": pd.NaT, "var": pd.NaT, "std": pd.NaT, "nunique": 12236, } ed_metrics = ed_timestamps.agg( self.funcs + self.extended_funcs + ["nunique"], numeric_only=False ) ed_metrics_dict = ed_metrics["timestamp"].to_dict() ed_metrics_dict.pop("median") # Median is tested below. for key, expected_value in expected_values.items(): assert_almost_equal(ed_metrics_dict[key], expected_value)
def test_today() -> None: c.assert_almost_equal( datemore.datetime.Datetime.today().native(), timezone.localize(datetime.datetime.today()), )
def test_today() -> None: c.assert_almost_equal(datemore.date.Date.today().native(), datetime.date.today())