Commit 785b815
authored
fix: preserve column names with spaces in wr.redshift.copy() (#3298)
* fix: preserve column names with spaces in wr.redshift.copy()
Passes flavor=None to internal s3.to_parquet call to prevent pyarrow spark flavor from sanitizing column names (spaces → underscores). Fixes #3293
* feat: add sanitize_column_names parameter to wr.redshift.copy()
Problem:
wr.redshift.copy() internally calls s3.to_parquet() which defaults to
pyarrow flavor='spark'. This causes column names with spaces to be
silently renamed (e.g. "my col" → "my_col"), leading to a mismatch
between the DataFrame schema and the Redshift table schema.
Solution:
Add an optional sanitize_column_names parameter (default=True) to
wr.redshift.copy() that controls whether pyarrow sanitizes column names.
- sanitize_column_names=True (default): preserves existing behavior,
column names are sanitized for backward compatibility.
- sanitize_column_names=False: passes flavor=None to the internal
s3.to_parquet() call, preserving original column names including spaces.
This is a non-breaking change — existing users are unaffected since
the default value maintains the current behavior.
Changes:
- Added sanitize_column_names: bool = True parameter to copy()
- Updated pyarrow_additional_kwargs in s3.to_parquet() call accordingly
- Added docstring for the new parameter
- Added test case for sanitize_column_names=False behavior
Fixes #3293
* test: add test for sanitize_column_names=False in wr.redshift.copy()
test: add test for sanitize_column_names=False in wr.redshift.copy()
* style: fix ruff formatting - remove trailing whitespace
style: fix ruff formatting - remove trailing whitespace
* style: fix ruff formatting - remove trailing whitespace in _write.py
style: fix ruff formatting - remove trailing whitespace in _write.py
* style: fix ruff formatting in test_redshift.py
style: fix ruff formatting in test_redshift.py
* fix: add required blank line in docstring for ruff D410/D411
fix: add required blank line in docstring for ruff D410/D411
* fix: remove trailing whitespace in sanitize_column_names docstring
fix: remove trailing whitespace in sanitize_column_names docstring
* fix: replace sanitize_column_names with pyarrow_additional_kwargs
* fix: update test to use pyarrow_additional_kwargs instead of sanitize_column_names
---------1 parent 9f70cfa commit 785b815
2 files changed
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
574 | 574 | | |
575 | 575 | | |
576 | 576 | | |
| 577 | + | |
577 | 578 | | |
578 | 579 | | |
579 | 580 | | |
| |||
687 | 688 | | |
688 | 689 | | |
689 | 690 | | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
690 | 694 | | |
691 | 695 | | |
692 | 696 | | |
| |||
715 | 719 | | |
716 | 720 | | |
717 | 721 | | |
| 722 | + | |
718 | 723 | | |
719 | 724 | | |
720 | 725 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1657 | 1657 | | |
1658 | 1658 | | |
1659 | 1659 | | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
0 commit comments