mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
chore: bump pyarrow and pandas (#12882)
* bump pyarrow and pandas * remove df copy
This commit is contained in:
@@ -23,7 +23,7 @@ import hashlib
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from typing import Any, Tuple, List
|
||||
from typing import Any, Tuple, List, Optional
|
||||
from unittest.mock import Mock, patch
|
||||
from tests.fixtures.birth_names_dashboard import load_birth_names_dashboard_with_slices
|
||||
|
||||
@@ -1135,28 +1135,38 @@ class TestUtils(SupersetTestCase):
|
||||
assert extract_dataframe_dtypes(df) == [col[1] for col in cols]
|
||||
|
||||
def test_normalize_dttm_col(self):
|
||||
def normalize_col(
|
||||
df: pd.DataFrame,
|
||||
timestamp_format: Optional[str],
|
||||
offset: int,
|
||||
time_shift: Optional[timedelta],
|
||||
) -> pd.DataFrame:
|
||||
df = df.copy()
|
||||
normalize_dttm_col(df, timestamp_format, offset, time_shift)
|
||||
return df
|
||||
|
||||
ts = pd.Timestamp(2021, 2, 15, 19, 0, 0, 0)
|
||||
df = pd.DataFrame([{"__timestamp": ts, "a": 1}])
|
||||
|
||||
# test regular (non-numeric) format
|
||||
assert normalize_dttm_col(df, None, 0, None)[DTTM_ALIAS][0] == ts
|
||||
assert normalize_dttm_col(df, "epoch_ms", 0, None)[DTTM_ALIAS][0] == ts
|
||||
assert normalize_dttm_col(df, "epoch_s", 0, None)[DTTM_ALIAS][0] == ts
|
||||
assert normalize_col(df, None, 0, None)[DTTM_ALIAS][0] == ts
|
||||
assert normalize_col(df, "epoch_ms", 0, None)[DTTM_ALIAS][0] == ts
|
||||
assert normalize_col(df, "epoch_s", 0, None)[DTTM_ALIAS][0] == ts
|
||||
|
||||
# test offset
|
||||
assert normalize_dttm_col(df, None, 1, None)[DTTM_ALIAS][0] == pd.Timestamp(
|
||||
assert normalize_col(df, None, 1, None)[DTTM_ALIAS][0] == pd.Timestamp(
|
||||
2021, 2, 15, 20, 0, 0, 0
|
||||
)
|
||||
|
||||
# test offset and timedelta
|
||||
assert normalize_dttm_col(df, None, 1, timedelta(minutes=30))[DTTM_ALIAS][
|
||||
assert normalize_col(df, None, 1, timedelta(minutes=30))[DTTM_ALIAS][
|
||||
0
|
||||
] == pd.Timestamp(2021, 2, 15, 20, 30, 0, 0)
|
||||
|
||||
# test numeric epoch_s format
|
||||
df = pd.DataFrame([{"__timestamp": ts.timestamp(), "a": 1}])
|
||||
assert normalize_dttm_col(df, "epoch_s", 0, None)[DTTM_ALIAS][0] == ts
|
||||
assert normalize_col(df, "epoch_s", 0, None)[DTTM_ALIAS][0] == ts
|
||||
|
||||
# test numeric epoch_ms format
|
||||
df = pd.DataFrame([{"__timestamp": ts.timestamp() * 1000, "a": 1}])
|
||||
assert normalize_dttm_col(df, "epoch_ms", 0, None)[DTTM_ALIAS][0] == ts
|
||||
assert normalize_col(df, "epoch_ms", 0, None)[DTTM_ALIAS][0] == ts
|
||||
|
||||
Reference in New Issue
Block a user