From commits-return-2885-archive-asf-public=cust-asf.ponee.io@superset.incubator.apache.org Mon Jul 1 22:44:10 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id B2662180670 for ; Tue, 2 Jul 2019 00:44:09 +0200 (CEST) Received: (qmail 22490 invoked by uid 500); 1 Jul 2019 22:44:09 -0000 Mailing-List: contact commits-help@superset.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@superset.incubator.apache.org Delivered-To: mailing list commits@superset.incubator.apache.org Received: (qmail 22480 invoked by uid 99); 1 Jul 2019 22:44:09 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Jul 2019 22:44:09 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 64F2987AD7; Mon, 1 Jul 2019 22:44:08 +0000 (UTC) Date: Mon, 01 Jul 2019 22:44:08 +0000 To: "commits@superset.apache.org" Subject: [incubator-superset] branch master updated: [Viz] transpose pivot table (#7325) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <156202104776.19955.7514553960867338544@gitbox.apache.org> From: maximebeauchemin@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: incubator-superset X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 3b2ac203962f4c75456d5d7bc084073a46477c30 X-Git-Newrev: 459276f00d87b3368366941d781baf9ef2acf1f1 X-Git-Rev: 459276f00d87b3368366941d781baf9ef2acf1f1 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 459276f [Viz] transpose pivot table (#7325) 459276f is described below commit 459276f00d87b3368366941d781baf9ef2acf1f1 Author: Yongjie Zhao AuthorDate: Tue Jul 2 06:44:01 2019 +0800 [Viz] transpose pivot table (#7325) --- .../assets/src/explore/controlPanels/PivotTable.js | 1 + superset/assets/src/explore/controls.jsx | 7 +++++++ superset/viz.py | 22 ++++++++++++++++------ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/superset/assets/src/explore/controlPanels/PivotTable.js b/superset/assets/src/explore/controlPanels/PivotTable.js index 71e754e..38b1078 100644 --- a/superset/assets/src/explore/controlPanels/PivotTable.js +++ b/superset/assets/src/explore/controlPanels/PivotTable.js @@ -36,6 +36,7 @@ export default { controlSetRows: [ ['pandas_aggfunc', 'pivot_margins'], ['number_format', 'combine_metric'], + ['transpose_pivot'], ], }, ], diff --git a/superset/assets/src/explore/controls.jsx b/superset/assets/src/explore/controls.jsx index feba265..2ae104b 100644 --- a/superset/assets/src/explore/controls.jsx +++ b/superset/assets/src/explore/controls.jsx @@ -471,6 +471,13 @@ export const controls = { description: t('Display total row/column'), }, + transpose_pivot: { + type: 'CheckboxControl', + label: t('Transpose Pivot'), + default: false, + description: t('Swap Groups and Columns'), + }, + show_markers: { type: 'CheckboxControl', label: t('Show Markers'), diff --git a/superset/viz.py b/superset/viz.py index a9a1aa0..7404a7f 100644 --- a/superset/viz.py +++ b/superset/viz.py @@ -654,15 +654,21 @@ class PivotTableViz(BaseViz): def query_obj(self): d = super().query_obj() - groupby = self.form_data.get("groupby") - columns = self.form_data.get("columns") - metrics = self.form_data.get("metrics") + groupby = self.form_data.get('groupby') + columns = self.form_data.get('columns') + metrics = self.form_data.get('metrics') + transpose = self.form_data.get('transpose_pivot') if not columns: columns = [] if not groupby: groupby = [] if not groupby: raise Exception(_("Please choose at least one 'Group by' field ")) + if transpose and not columns: + raise Exception(_(( + "Please choose at least one 'Columns' field when " + "select 'Transpose Pivot' option" + ))) if not metrics: raise Exception(_("Please choose at least one metric")) if any(v in groupby for v in columns) or any(v in columns for v in groupby): @@ -679,10 +685,14 @@ class PivotTableViz(BaseViz): if aggfunc == "sum": aggfunc = lambda x: x.sum(min_count=1) # noqa: E731 + groupby = self.form_data.get('groupby') + columns = self.form_data.get('columns') + if self.form_data.get('transpose_pivot'): + groupby, columns = columns, groupby df = df.pivot_table( - index=self.form_data.get("groupby"), - columns=self.form_data.get("columns"), - values=[utils.get_metric_name(m) for m in self.form_data.get("metrics")], + index=groupby, + columns=columns, + values=[utils.get_metric_name(m) for m in self.form_data.get('metrics')], aggfunc=aggfunc, margins=self.form_data.get("pivot_margins"), dropna=False,