GitHub user dosubot[bot] added a comment to the discussion: Get dataset 
description and columns description

<!-- Answer -->
To modify the `superset/datasets/schemas.py` and `core.py` files to read 
`dataset_description` and `column_descriptions` for use in `excel.py`, follow 
these steps:

1. **Modify `superset/datasets/schemas.py`**: Ensure that the dataset and 
column descriptions are accessible. This file already includes schema classes 
with description fields, so you might not need to modify it directly. However, 
ensure that these fields are being populated correctly when datasets and 
columns are created or updated.

2. **Modify `core.py`**: You need to create functions to retrieve the dataset 
and column descriptions. Here's a basic example of how you might implement 
these functions:

```python
def get_dataset_description(dataset_id: int) -> str:
    # Fetch the dataset description from the database using the dataset_id
    # This is a placeholder implementation; replace it with actual database 
access logic
    dataset = get_dataset_by_id(dataset_id)  # Assume this function fetches the 
dataset object
    return dataset.description if dataset else ""

def get_column_descriptions(dataset_id: int) -> dict:
    # Fetch column descriptions for a given dataset_id
    # This is a placeholder implementation; replace it with actual database 
access logic
    dataset = get_dataset_by_id(dataset_id)  # Assume this function fetches the 
dataset object
    if not dataset:
        return {}

    column_descriptions = {}
    for column in dataset.columns:
        column_descriptions[column.name] = column.description

    return column_descriptions
```

3. **Integrate with `excel.py`**: Use these functions to retrieve descriptions 
and pass them to the `df_to_excel_with_descriptions` function. Here's how you 
might call these functions and use them in `excel.py`:

```python
def export_to_excel(dataset_id: int, df: pd.DataFrame, **kwargs: Any) -> Any:
    # Retrieve descriptions
    dataset_description = get_dataset_description(dataset_id)
    column_descriptions = get_column_descriptions(dataset_id)

    # Export to Excel with descriptions
    return df_to_excel_with_descriptions(df, dataset_description, 
column_descriptions, **kwargs)
```

Ensure that you replace the placeholder logic in `get_dataset_description` and 
`get_column_descriptions` with actual database queries or ORM calls to fetch 
the dataset and column descriptions from your data source.


<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*

---
<sup>Help Dosu learn! Give it feedback: [Great 
Response](https://app.dosu.dev/response-feedback/2ef4b63e-2fa0-4607-b72d-b6fcdbea1762?feedback_type=great_response)
 | [Irrelevant 
Answer](https://app.dosu.dev/response-feedback/2ef4b63e-2fa0-4607-b72d-b6fcdbea1762?feedback_type=irrelevant_answer)
 | [Incorrect 
Sources](https://app.dosu.dev/response-feedback/2ef4b63e-2fa0-4607-b72d-b6fcdbea1762?feedback_type=incorrect_sources)
 | [Too 
Verbose](https://app.dosu.dev/response-feedback/2ef4b63e-2fa0-4607-b72d-b6fcdbea1762?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/2ef4b63e-2fa0-4607-b72d-b6fcdbea1762?feedback_type=hallucination)
 | [Bug 
Report](https://app.dosu.dev/response-feedback/2ef4b63e-2fa0-4607-b72d-b6fcdbea1762?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/2ef4b63e-2fa0-4607-b72d-b6fcdbea1762?feedback_type=other)</sup>


GitHub link: 
https://github.com/apache/superset/discussions/33504#discussioncomment-13186262

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to