You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@sedona.apache.org by "jiayuasu (via GitHub)" <gi...@apache.org> on 2026/05/26 07:05:50 UTC
[PR] feat(python/sedonadb): add DataFrame.rename [sedona-db]
jiayuasu opened a new pull request, #878:
URL: https://github.com/apache/sedona-db/pull/878
Continues Phase P2 of #791 with `DataFrame.rename`. Same shape as `drop` from #871 — small schema op, strings only, varargs-style (well, dict-style) API instead of pandas' `columns=` keyword.
## API
```python
df.rename({"a": "x"})
df.rename({"a": "x", "b": "y"})
```
- **Single `dict[str, str]` arg.** No `columns=` kwarg.
- **Direction is `{old: new}`** — matches Polars and the inner shape of `pandas.rename(columns={...})`. Not Ibis's kwarg-flipped style.
- **Strings only** for both keys and values; no `Expr`.
- **Multi-rename in one call**, applied as a single plan transformation.
## Validation
All Python-side, locked with exact-message tests where the message is the feature being verified:
- Empty dict → `ValueError`.
- Non-dict arg / non-str key or value → `TypeError`.
- Unknown old-name → `KeyError` listing available columns. Forced by DataFusion's `with_column_renamed` being permissive (same trap as `drop_columns`).
- Final-state collisions (`{"a": "z", "b": "z"}` or `{"a": "b"}` when `b` already exists) → `ValueError("duplicate column names")`.
## Swap-pair behavior (worth flagging)
`{"a": "b", "b": "a"}` has a unique final schema `[b, a]` so the Python-side collision check passes. But DataFusion applies renames sequentially, and the intermediate state after `a→b` collides with the original `b`. The error surfaces as `SedonaError` from plan-build with message `Projections require unique expression names...`.
I considered building a rename-graph and detecting cycles Python-side, but the DataFusion error is correct, clear-enough, and trying to reorder Python-side would either reimplement DataFusion's check or miss edge cases. Locked in `test_rename_swap_pair_raises_at_plan_build`. Users wanting a swap route through a temporary name explicitly.
## Tests
13 in `tests/expr/test_dataframe_rename.py`:
- **Positive**: single, multi, column-order preservation.
- **Lazy return**: `isinstance(out, DataFrame)`.
- **Errors**: empty dict; non-dict; non-str key; non-str value; `columns=` kwarg; unknown old-name (exact `KeyError` message); rename-onto-existing collision; new-name-to-new-name collision; sequential-application swap.
Local: 13 unit + 20 doctests + `ruff format` + `ruff check` all clean.
--
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: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(python/sedonadb): add DataFrame.rename [sedona-db]
Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu commented on PR #878:
URL: https://github.com/apache/sedona-db/pull/878#issuecomment-4549571261
> My preference would be to skip this one for now...it can be replicated with a one liner as a workaround (`df.select(*[col(k).alias(v) for k, v in mapping.items()])`) and there is more important APIs to surface like grouping, aggregation, join, and UDFs.
>
> I also very much dislike the Pandas rename syntax (`rename(a="b")` is easier to type for those of us still typing this stuff)
Fine by me. Moving on to the next operator then.
--
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: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat(python/sedonadb): add DataFrame.rename [sedona-db]
Posted by "jiayuasu (via GitHub)" <gi...@apache.org>.
jiayuasu closed pull request #878: feat(python/sedonadb): add DataFrame.rename
URL: https://github.com/apache/sedona-db/pull/878
--
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: issues-unsubscribe@sedona.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org