Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds opt-in tooling to work with column aliases vs attribute names in Dataframely schemas, enabling users to explicitly rename aliased DataFrame columns back to schema attribute identifiers (Pydantic-like ergonomics).
Changes:
- Add
use_attribute_namesschema class parameter to control whether schema column identifiers use attribute names vs aliases. - Track attribute→alias metadata and expose alias→attribute mapping via
_alias_mapping(). - Add
Schema.undo_aliases()to rename DataFrame/LazyFrame columns from alias names to attribute names, plus tests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
dataframely/_base_schema.py |
Extends schema metaclass/metadata to support use_attribute_names and alias mappings. |
dataframely/schema.py |
Adds Schema.undo_aliases() public helper to rename columns using alias mapping. |
tests/columns/test_alias.py |
Adds tests for inheritance behavior, alias mapping, and undo_aliases() on eager/lazy frames. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #293 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 54 54
Lines 3121 3127 +6
=========================================
+ Hits 3121 3127 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
added 7 commits
March 4, 2026 00:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #292
I went ahead and implemented a fix before approval but this is more to provide a concrete basis for discussion. But of course I am curious about your though and would be happy to change the api or anything.
Motivation
Users coming from pydantic may find the current alias behavior surprising. In pydantic, the alias is used for input parsing, but the attribute name is used when accessing the data:
User might want to get the same behavior with column names in the dataframe.
This PR provides tools to achieve similar behavior in dataframely when desired.
Changes
This PR adds two features for working with column aliases:
use_attribute_namesclass parameter - Controls howcolumn.nameis resolved when accessing columns via schema attributesundo_aliases()method - Renames DataFrame columns from their alias names to their attribute namesFeatures
use_attribute_namesclass parameterWhen set to
True, accessing a column via a schema attribute returns the attribute name instead of the alias:This setting is inherited by child schemas.
undo_aliases()methodRenames columns from their alias names to their attribute names:
Works with both
DataFrameandLazyFrame.Important Notes
validate()does NOT rename columns - The validated DataFrame keeps the original column names (aliases)undo_aliases()when you want to rename columns to attribute namesuse_attribute_namesdefaults toFalseExample Workflow