You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "dosubot[bot] (via GitHub)" <gi...@apache.org> on 2026/05/02 03:20:06 UTC
Re: [D] Get dataset description and columns description [superset]
GitHub user dosubot[bot] edited a comment on the discussion: Get dataset description and columns description
<!-- Answer -->
To include dataset and column descriptions in the Excel export, you can follow these steps:
1. **Retrieve Descriptions**: First, ensure you have access to the dataset and column descriptions. These are defined in various parts of the Superset codebase, such as in the `superset/datasets/schemas.py` file and the frontend interface in `superset-frontend/packages/superset-ui-core/src/query/types/Datasource.ts` <sup>[[1]](https://github.com/apache/superset/blob/master/superset/datasets/schemas.py)</sup><sup>[[2]](https://github.com/apache/superset/blob/master/superset-frontend/packages/superset-ui-core/src/query/types/Datasource.ts)</sup>.
2. **Modify `core.py`**: Although `core.py` does not directly handle descriptions, you can use functions like `get_column_name` and `get_column_names` to retrieve column metadata. You might need to extend these functions or create new ones to fetch descriptions if they are not already included <sup>[[3]](https://github.com/apache/superset/blob/master/tests/unit_tests/core_tests.py)</sup>.
3. **Modify `excel.py`**: In `excel.py`, you can modify the `df_to_excel` function to add a new sheet for descriptions. Use the `xlsxwriter` library to create a workbook and add worksheets. Here's a basic example of how you can add a new sheet for descriptions:
```python
import io
import pandas as pd
import xlsxwriter
def df_to_excel_with_descriptions(df: pd.DataFrame, dataset_description: str, column_descriptions: dict, **kwargs: Any) -> Any:
output = io.BytesIO()
# Quote formulas to prevent malicious injections
df = quote_formulas(df)
with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
# Write the main data to the first sheet
df.to_excel(writer, sheet_name='Data', **kwargs)
# Add a new sheet for descriptions
workbook = writer.book
description_sheet = workbook.add_worksheet('Descriptions')
# Write dataset description
description_sheet.write(0, 0, 'Dataset Description')
description_sheet.write(0, 1, dataset_description)
# Write column descriptions
description_sheet.write(1, 0, 'Column Name')
description_sheet.write(1, 1, 'Description')
row = 2
for column, description in column_descriptions.items():
description_sheet.write(row, 0, column)
description_sheet.write(row, 1, description)
row += 1
return output.getvalue()
```
In this example, `dataset_description` is a string containing the dataset's description, and `column_descriptions` is a dictionary where keys are column names and values are their descriptions. You will need to pass these to the function when calling it.
By implementing these changes, you can include the dataset and column descriptions in a separate sheet in the exported Excel file.
<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=reply-with-mention&utm_term=apache%2Fsuperset).*
---
Share context across your team and agents. Try [Dosu](https://dosu.dev?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-tagline&utm_term=apache%2Fsuperset).
[](https://app.dosu.dev/response-feedback?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-feedback&utm_term=apache%2Fsuperset&message_id=6373ebbc-40a1-40ae-bd70-c40954a1cd48) [](https://github.dosu.com/apache/superset?utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-learn-repo&utm_term=apache%2Fsuperset) [](https://app.dosu.dev/signup?referrer=openSource&source=github-footer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-comment-footer-20260415&utm_content=knowledge-infrastructure-add-team&utm_term=apache%2Fsuperset)
GitHub link: https://github.com/apache/superset/discussions/33504#discussioncomment-13186210
----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: notifications-unsubscribe@superset.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org