fix: time comparision (#19659)

This commit is contained in:
Yongjie Zhao
2022-04-12 18:19:22 +08:00
committed by GitHub
parent 5c63df522a
commit d7dd4119d4
2 changed files with 23 additions and 24 deletions

View File

@@ -44,9 +44,9 @@ def test_compare_diff():
"""
label y z difference__y__z
2019-01-01 x 2.0 2.0 0.0
2019-01-02 y 2.0 4.0 2.0
2019-01-05 z 2.0 10.0 8.0
2019-01-07 q 2.0 8.0 6.0
2019-01-02 y 2.0 4.0 -2.0
2019-01-05 z 2.0 10.0 -8.0
2019-01-07 q 2.0 8.0 -6.0
"""
assert post_df.equals(
pd.DataFrame(
@@ -55,7 +55,7 @@ def test_compare_diff():
"label": ["x", "y", "z", "q"],
"y": [2.0, 2.0, 2.0, 2.0],
"z": [2.0, 4.0, 10.0, 8.0],
"difference__y__z": [0.0, 2.0, 8.0, 6.0],
"difference__y__z": [0.0, -2.0, -8.0, -6.0],
},
)
)
@@ -73,7 +73,7 @@ def test_compare_diff():
index=timeseries_df2.index,
data={
"label": ["x", "y", "z", "q"],
"difference__y__z": [0.0, 2.0, 8.0, 6.0],
"difference__y__z": [0.0, -2.0, -8.0, -6.0],
},
)
)
@@ -90,9 +90,9 @@ def test_compare_percentage():
"""
label y z percentage__y__z
2019-01-01 x 2.0 2.0 0.0
2019-01-02 y 2.0 4.0 1.0
2019-01-05 z 2.0 10.0 4.0
2019-01-07 q 2.0 8.0 3.0
2019-01-02 y 2.0 4.0 -0.50
2019-01-05 z 2.0 10.0 -0.80
2019-01-07 q 2.0 8.0 -0.75
"""
assert post_df.equals(
pd.DataFrame(
@@ -101,7 +101,7 @@ def test_compare_percentage():
"label": ["x", "y", "z", "q"],
"y": [2.0, 2.0, 2.0, 2.0],
"z": [2.0, 4.0, 10.0, 8.0],
"percentage__y__z": [0.0, 1.0, 4.0, 3.0],
"percentage__y__z": [0.0, -0.50, -0.80, -0.75],
},
)
)
@@ -117,10 +117,10 @@ def test_compare_ratio():
)
"""
label y z ratio__y__z
2019-01-01 x 2.0 2.0 1.0
2019-01-02 y 2.0 4.0 2.0
2019-01-05 z 2.0 10.0 5.0
2019-01-07 q 2.0 8.0 4.0
2019-01-01 x 2.0 2.0 1.00
2019-01-02 y 2.0 4.0 0.50
2019-01-05 z 2.0 10.0 0.20
2019-01-07 q 2.0 8.0 0.25
"""
assert post_df.equals(
pd.DataFrame(
@@ -129,7 +129,7 @@ def test_compare_ratio():
"label": ["x", "y", "z", "q"],
"y": [2.0, 2.0, 2.0, 2.0],
"z": [2.0, 4.0, 10.0, 8.0],
"ratio__y__z": [1.0, 2.0, 5.0, 4.0],
"ratio__y__z": [1.00, 0.50, 0.20, 0.25],
},
)
)
@@ -209,14 +209,14 @@ def test_compare_after_pivot():
difference__count_metric__sum_metric
country UK US
dttm
2019-01-01 4 4
2019-01-02 4 4
2019-01-01 -4 -4
2019-01-02 -4 -4
"""
flat_df = pp.flatten(compared_df)
"""
dttm difference__count_metric__sum_metric, UK difference__count_metric__sum_metric, US
0 2019-01-01 4 4
1 2019-01-02 4 4
0 2019-01-01 -4 -4
1 2019-01-02 -4 -4
"""
assert flat_df.equals(
pd.DataFrame(
@@ -224,10 +224,10 @@ def test_compare_after_pivot():
"dttm": pd.to_datetime(["2019-01-01", "2019-01-02"]),
FLAT_COLUMN_SEPARATOR.join(
["difference__count_metric__sum_metric", "UK"]
): [4, 4],
): [-4, -4],
FLAT_COLUMN_SEPARATOR.join(
["difference__count_metric__sum_metric", "US"]
): [4, 4],
): [-4, -4],
}
)
)