altef opened a new issue #11988: URL: https://github.com/apache/incubator-superset/issues/11988
For some datasets, using percentage metrics results in the error: `unsupported operand type(s) for /: 'decimal.Decimal' and 'float'`. I'm using Postgres, and I've traced this back a few ways - 1. It _doesn't_ happen if the column is of type INT (under dataset/columns/Data Type). 2. It _does_ seem to occur if the column is of type BIGINT or NUMERIC. 3. It appears to come from: (https://github.com/apache/incubator-superset/blob/master/superset/viz.py#L780) Changing that line to `(df[percent_columns].astype(float).div(df[percent_columns].sum()).add_prefix("%")),` seems to fix the issue for me, but it may have ramifications I'm unaware of (I'm not very familiar with this portion of the code-base). *Disclaimer:* This is on yesterday's master branch. (I'm not sure if we're supposed to report bugs on master or not.) ### Expected results Ideally it would show a table with data, including percentages. ### Actual results It shows the error message `unsupported operand type(s) for /: 'decimal.Decimal' and 'float'`. #### Screenshots   #### How to reproduce the bug 1. Create a table and add some data to it: ```sql CREATE TABLE decimaltest ( "name" varchar NULL, value int8 NULL ); INSERT INTO decimaltest ("name", value) VALUES ('one', 478696), ('two', 344274), ('three', 215815); ``` I specified `int8` since that seems to result in a `BIG INT` classification. 2. Add the dataset to Superset. 3. Create a new chart on the dataset, of type Table. Set `GROUP BY` to `name`, and `PERCENTAGE METRICS` to `SUM(value)`. 4. Click `RUN`. 5. See error. ### Environment (please complete the following information): - superset version: `0.999.0dev` - python version: `3.7.9` - node.js version: `v13.11.0` ### Checklist Make sure to follow these steps before submitting your issue - thank you! - [x] I have checked the superset logs for python stacktraces and included it here as text if there are any. ``` ERROR:superset.views.base:unsupported operand type(s) for /: 'decimal.Decimal' and 'float' Traceback (most recent call last): File "/home/ubuntu/newersuperset/venv/lib/python3.7/site-packages/pandas/core/ops/array_ops.py", line 143, in na_arithmetic_op result = expressions.evaluate(op, left, right) File "/home/ubuntu/newersuperset/venv/lib/python3.7/site-packages/pandas/core/computation/expressions.py", line 233, in evaluate return _evaluate(op, op_str, a, b) # type: ignore File "/home/ubuntu/newersuperset/venv/lib/python3.7/site-packages/pandas/core/computation/expressions.py", line 68, in _evaluate_standard return op(a, b) TypeError: unsupported operand type(s) for /: 'decimal.Decimal' and 'float' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/ubuntu/newersuperset/superset/views/base.py", line 178, in wraps return f(self, *args, **kwargs) File "/home/ubuntu/newersuperset/superset/utils/log.py", line 125, in wrapper value = f(*args, **kwargs) File "/home/ubuntu/newersuperset/superset/utils/cache.py", line 108, in wrapper return f(*args, **kwargs) File "/home/ubuntu/newersuperset/superset/views/core.py", line 537, in explore_json return self.generate_json(viz_obj, response_type) File "/home/ubuntu/newersuperset/superset/views/core.py", line 433, in generate_json payload = viz_obj.get_payload() File "/home/ubuntu/newersuperset/superset/viz.py", line 488, in get_payload payload["data"] = self.get_data(df) File "/home/ubuntu/newersuperset/superset/viz.py", line 780, in get_data (df[percent_columns].div(df[percent_columns].sum()).add_prefix("%")), File "/home/ubuntu/newersuperset/venv/lib/python3.7/site-packages/pandas/core/ops/__init__.py", line 651, in f new_data = self._combine_frame(other, na_op, fill_value) File "/home/ubuntu/newersuperset/venv/lib/python3.7/site-packages/pandas/core/frame.py", line 5870, in _combine_frame new_data = ops.dispatch_to_series(self, other, _arith_op) File "/home/ubuntu/newersuperset/venv/lib/python3.7/site-packages/pandas/core/ops/__init__.py", line 275, in dispatch_to_series bm = left._mgr.operate_blockwise(right._mgr, array_op) File "/home/ubuntu/newersuperset/venv/lib/python3.7/site-packages/pandas/core/internals/managers.py", line 364, in operate_blockwise return operate_blockwise(self, other, array_op) File "/home/ubuntu/newersuperset/venv/lib/python3.7/site-packages/pandas/core/internals/ops.py", line 38, in operate_blockwise res_values = array_op(lvals, rvals) File "/home/ubuntu/newersuperset/venv/lib/python3.7/site-packages/pandas/core/ops/array_ops.py", line 190, in arithmetic_op res_values = na_arithmetic_op(lvalues, rvalues, op) File "/home/ubuntu/newersuperset/venv/lib/python3.7/site-packages/pandas/core/ops/array_ops.py", line 150, in na_arithmetic_op result = masked_arith_op(left, right, op) File "/home/ubuntu/newersuperset/venv/lib/python3.7/site-packages/pandas/core/ops/array_ops.py", line 92, in masked_arith_op result[mask] = op(xrav[mask], yrav[mask]) TypeError: unsupported operand type(s) for /: 'decimal.Decimal' and 'float' ``` - [ ] I have reproduced the issue with at least the latest released version of superset. ``` I've only tried on master, which... This may answer my earlier question about reporting bugs on master. I'm going to submit it anyway, just in case, but apologies if that is not the accepted approach. ``` - [x] I have checked the issue tracker for the same issue and I haven't found one similar. ``` Though I am not the best at constructing search queries. If something similar has been reported, apologies. ``` ### Additional context None ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
