Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(python): Ensure write_excel recognises the Array dtype and writes it out as a string #20994

Merged
merged 1 commit into from
Feb 1, 2025

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Jan 30, 2025

The function was written before we had the Array dtype and the is_nested() method on the dtype class, so explicitly enumerated the dtypes that needed to be cast to string on sheet export - and therefore missed Array.

  • Now takes advantage of .is_nested() to guarantee that we consistently identify dtypes that Excel doesn't work with natively (List, Array, Struct).

  • Also made a few micro-optimisations, eg: df.height instead of len(df), and df.width instead of len(df.columns). Note that we can make this change in more places, avoiding the indirect/function call - I'll follow up with a separate PR for that.

@github-actions github-actions bot added fix Bug fix python Related to Python Polars labels Jan 30, 2025
@alexander-beedie alexander-beedie added the A-io-spreadsheet Area: reading/writing Excel/ODS files label Jan 30, 2025
@alexander-beedie alexander-beedie force-pushed the fix-write-excel-array branch 3 times, most recently from 7a5a994 to f1bb6da Compare January 30, 2025 08:27
Copy link

codecov bot commented Jan 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.10%. Comparing base (c3d317e) to head (a9d2a5b).
Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #20994      +/-   ##
==========================================
- Coverage   79.21%   79.10%   -0.12%     
==========================================
  Files        1583     1583              
  Lines      225082   225843     +761     
  Branches     2581     2600      +19     
==========================================
+ Hits       178299   178646     +347     
- Misses      46193    46606     +413     
- Partials      590      591       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ritchie46
Copy link
Member

Also made a few micro-optimisations, eg: df.height instead of len(df), and df.width instead of len(df.columns). Note that we can make this change in more places, avoiding the indirect/function call - I'll follow up with a separate PR for that.

Yeah, good one. Especially the df.columns, which is an allocation.

@ritchie46 ritchie46 closed this Feb 1, 2025
@ritchie46 ritchie46 reopened this Feb 1, 2025
@ritchie46 ritchie46 merged commit 4c22f1e into pola-rs:main Feb 1, 2025
29 checks passed
@alexander-beedie alexander-beedie deleted the fix-write-excel-array branch February 1, 2025 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-io-spreadsheet Area: reading/writing Excel/ODS files fix Bug fix python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants