You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2020/03/17 17:47:16 UTC
[incubator-superset] branch master updated: fix: big number to
handle NULL as it did in the past (#9314)
This is an automated email from the ASF dual-hosted git repository.
maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push:
new 6cf36c9 fix: big number to handle NULL as it did in the past (#9314)
6cf36c9 is described below
commit 6cf36c91ea95b501491cbc828709172cf29b21cf
Author: Maxime Beauchemin <ma...@gmail.com>
AuthorDate: Tue Mar 17 10:46:59 2020 -0700
fix: big number to handle NULL as it did in the past (#9314)
---
superset/viz.py | 4 ++--
tests/viz_tests.py | 28 ++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/superset/viz.py b/superset/viz.py
index 433fede..13bde2a 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -1126,8 +1126,8 @@ class BigNumberViz(BaseViz):
index=DTTM_ALIAS,
columns=[],
values=self.metric_labels,
- fill_value=0,
- aggfunc=sum,
+ dropna=False,
+ aggfunc=np.min, # looking for any (only) value, preserving `None`
)
df = self.apply_rolling(df)
df[DTTM_ALIAS] = df.index
diff --git a/tests/viz_tests.py b/tests/viz_tests.py
index ec318e6..80da72e 100644
--- a/tests/viz_tests.py
+++ b/tests/viz_tests.py
@@ -1243,3 +1243,31 @@ class TimeSeriesVizTestCase(SupersetTestCase):
.tolist(),
[1.0, 1.5, 2.0, 2.5],
)
+
+
+class BigNumberVizTestCase(SupersetTestCase):
+ def test_get_data(self):
+ datasource = self.get_datasource_mock()
+ df = pd.DataFrame(
+ data={
+ DTTM_ALIAS: pd.to_datetime(
+ ["2019-01-01", "2019-01-02", "2019-01-05", "2019-01-07"]
+ ),
+ "y": [1.0, 2.0, 3.0, 4.0],
+ }
+ )
+ data = viz.BigNumberViz(datasource, {"metrics": ["y"]}).get_data(df)
+ self.assertEqual(data[2], {DTTM_ALIAS: pd.Timestamp("2019-01-05"), "y": 3})
+
+ def test_get_data_with_none(self):
+ datasource = self.get_datasource_mock()
+ df = pd.DataFrame(
+ data={
+ DTTM_ALIAS: pd.to_datetime(
+ ["2019-01-01", "2019-01-02", "2019-01-05", "2019-01-07"]
+ ),
+ "y": [1.0, 2.0, None, 4.0],
+ }
+ )
+ data = viz.BigNumberViz(datasource, {"metrics": ["y"]}).get_data(df)
+ assert np.isnan(data[2]["y"])