You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/09/20 18:57:02 UTC
[GitHub] [superset] eschutho commented on a diff in pull request #19810: feat(reports): xlsx attachments
eschutho commented on code in PR #19810:
URL: https://github.com/apache/superset/pull/19810#discussion_r975704282
##########
tests/integration_tests/reports/commands_tests.py:
##########
@@ -339,7 +339,7 @@ def create_report_slack_chart_with_csv():
report_schedule = create_report_notification(
slack_channel="slack_channel",
chart=chart,
- report_format=ReportDataFormat.DATA,
+ report_format=ReportDataFormat.CSV,
Review Comment:
@cemremengu Thanks for the pr! Can you also include some tests like these that also use `XLSX` as the data format?
##########
superset/reports/commands/execute.py:
##########
@@ -333,11 +334,25 @@ def _get_notification_content(self) -> NotificationContent:
error_text = "Unexpected missing screenshot"
elif (
self._report_schedule.chart
- and self._report_schedule.report_format == ReportDataFormat.DATA
+ and self._report_schedule.report_format == ReportDataFormat.CSV
+ ):
+ data = self._get_csv_data()
+ if not data:
+ error_text = "Unexpected missing csv file"
+ elif (
+ self._report_schedule.chart
+ and self._report_schedule.report_format == ReportDataFormat.XLSX
):
csv_data = self._get_csv_data()
if not csv_data:
- error_text = "Unexpected missing csv file"
+ error_text = "Unexpected missing csv data for xlsx"
+ else:
+ df = pd.read_csv(BytesIO(csv_data))
+ bio = BytesIO()
+ # pylint: disable=abstract-class-instantiated
+ with pd.ExcelWriter(bio, engine="openpyxl") as writer:
+ df.to_excel(writer, index=False)
+ data = bio.getvalue()
Review Comment:
I would recommend moving most of the csv and excel creation logic here to a new command called something like `_get_excel_data` so that it can be reusable, too.
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org