You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "squalou (via GitHub)" <gi...@apache.org> on 2023/03/15 10:35:30 UTC

[GitHub] [superset] squalou commented on issue #23375: Datatype not correctly exported (example to xlsx)

squalou commented on issue #23375:
URL: https://github.com/apache/superset/issues/23375#issuecomment-1469756997

   I *would* suggest a quick fix, but not sure I can manage a pull request
   
   here's the idea in `superset/common/query_context_processor.py`
   
   before
   ```py
   result = excel.df_to_excel(df, **config["EXCEL_EXPORT"])
   ```
   after
   
   ```py
   ndf = df.copy()                
   columns = list(df)
   for c in columns:
       logging.info(f"column {c} dtype is {df[c].dtypes}")
       if is_object_dtype(df[c]) and not is_string_dtype(df[c]):
           ndf[c] = pd.to_numeric(df[c], errors='ignore')
           logging.info(f"column {c} converted to numeric")
   
   result = excel.df_to_excel(ndf, **config["EXCEL_EXPORT"])
   
   ```
   
   This way, data not explicetely typed as string or dates or numeric ... get a chance to be silentely converted to a numeric.
   
   I have good results with this, maybe there's a more elegant way to proceed (especially no idea if doing a copy is useful as I don't know the big picture)
   


-- 
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