Skip to content

Commit

Permalink
feat(viz-plugins): add date formatting to pivot-table (#10637)
Browse files Browse the repository at this point in the history
* feat: make pivot table dates formattable

* Bump npm packages
  • Loading branch information
villebro committed Sep 5, 2020
1 parent 7a67a28 commit df1deb2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
12 changes: 6 additions & 6 deletions superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions superset-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"@superset-ui/legacy-plugin-chart-paired-t-test": "^0.14.9",
"@superset-ui/legacy-plugin-chart-parallel-coordinates": "^0.14.9",
"@superset-ui/legacy-plugin-chart-partition": "^0.14.9",
"@superset-ui/legacy-plugin-chart-pivot-table": "^0.14.14",
"@superset-ui/legacy-plugin-chart-pivot-table": "^0.14.21",
"@superset-ui/legacy-plugin-chart-rose": "^0.14.14",
"@superset-ui/legacy-plugin-chart-sankey": "^0.14.9",
"@superset-ui/legacy-plugin-chart-sankey-loop": "^0.14.9",
Expand All @@ -89,7 +89,7 @@
"@superset-ui/legacy-plugin-chart-world-map": "^0.14.16",
"@superset-ui/legacy-preset-chart-big-number": "^0.14.9",
"@superset-ui/legacy-preset-chart-deckgl": "^0.2.4",
"@superset-ui/legacy-preset-chart-nvd3": "^0.14.17",
"@superset-ui/legacy-preset-chart-nvd3": "^0.14.21",
"@superset-ui/number-format": "^0.14.9",
"@superset-ui/plugin-chart-table": "^0.14.16",
"@superset-ui/plugin-chart-word-cloud": "^0.14.9",
Expand Down
17 changes: 15 additions & 2 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
QueryMode,
to_adhoc,
)
from superset.utils.dates import datetime_to_epoch
from superset.utils.hashing import md5_sha_from_str

if TYPE_CHECKING:
Expand Down Expand Up @@ -825,8 +826,20 @@ def get_data(self, df: pd.DataFrame) -> VizData:
for metric in metrics:
aggfuncs[metric] = self.get_aggfunc(metric, df, self.form_data)

groupby = self.form_data.get("groupby")
columns = self.form_data.get("columns")
groupby = self.form_data.get("groupby") or []
columns = self.form_data.get("columns") or []

def _format_datetime(value: Any) -> Optional[str]:
if isinstance(value, str):
return f"__timestamp:{datetime_to_epoch(pd.Timestamp(value))}"
return None

for column_name in groupby + columns:
column = self.datasource.get_column(column_name)
if column and column.type in ("DATE", "DATETIME", "TIMESTAMP"):
ts = df[column_name].apply(_format_datetime)
df[column_name] = ts

if self.form_data.get("transpose_pivot"):
groupby, columns = columns, groupby

Expand Down

0 comments on commit df1deb2

Please sign in to comment.