Skip to content

feat: Add optional sqlalchemy_use_enum for dy.Enum#355

Merged
Andreas Albert (AndreasAlbertQC) merged 12 commits into
Quantco:mainfrom
jackoberman:feat/enum-sqlalchemy-use-enum
Jul 1, 2026
Merged

feat: Add optional sqlalchemy_use_enum for dy.Enum#355
Andreas Albert (AndreasAlbertQC) merged 12 commits into
Quantco:mainfrom
jackoberman:feat/enum-sqlalchemy-use-enum

Conversation

@jackoberman

Copy link
Copy Markdown
Contributor

Allow dy.Enum to emit sqlalchemy.Enum for to_sqlalchemy_columns when sqlalchemy_use_enum=True, with optional sqlalchemy_enum_name and column- name defaults for PostgreSQL native enum types.

Closes #354

Copilot AI review requested due to automatic review settings June 2, 2026 22:56
@github-actions github-actions Bot added the enhancement New feature or request label Jun 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds optional support for generating native SQLAlchemy ENUM types from dy.Enum columns (primarily for PostgreSQL / Alembic drift detection), plus accompanying docs and tests.

Changes:

  • Extend dy.Enum with sqlalchemy_use_enum and sqlalchemy_enum_name flags to emit sqlalchemy.Enum instead of CHAR/VARCHAR.
  • Add tests for SQLAlchemy column/type generation and for (de)serialization/matching behavior of the new flags.
  • Document how to enable native SQL enums and how enum type names are chosen.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
dataframely/columns/enum.py Implements SQLAlchemy native enum mapping and naming rules.
tests/columns/test_sqlalchemy_columns.py Verifies dialect-specific compilation/type naming and error behavior.
tests/column_types/test_enum.py Validates matches() semantics + as_dict/from_dict for new flags.
docs/guides/features/sql-generation.md Documents how to use the new native SQL enum feature.

Comment thread dataframely/columns/enum.py Outdated
Comment thread dataframely/columns/enum.py Outdated
Comment thread docs/guides/features/sql-generation.md Outdated
Comment thread docs/guides/features/sql-generation.md Outdated
Comment thread tests/columns/test_sqlalchemy_columns.py
Comment thread tests/columns/test_sqlalchemy_columns.py

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jack Oberman (@jackoberman) ! I think the functionality is solid, I just have a few suggestions to improve readability / organization. Let me know if anything's not clear.

Comment thread dataframely/columns/enum.py
Comment thread dataframely/columns/enum.py Outdated
Comment thread dataframely/columns/enum.py Outdated
Comment thread dataframely/columns/enum.py Outdated
Comment thread dataframely/columns/enum.py Outdated
Comment thread docs/guides/features/sql-generation.md Outdated
Comment thread docs/guides/features/sql-generation.md
Comment thread tests/column_types/test_enum.py
Comment thread tests/columns/test_sqlalchemy_columns.py
Comment thread dataframely/columns/enum.py Outdated
Allow dy.Enum to emit sqlalchemy.Enum for to_sqlalchemy_columns when
sqlalchemy_use_enum=True, with optional sqlalchemy_enum_name and column-
name defaults for PostgreSQL native enum types.

Closes Quantco#354

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jackoberman Jack Oberman (jackoberman) force-pushed the feat/enum-sqlalchemy-use-enum branch from 58e0727 to ba13eff Compare July 1, 2026 12:43
@jackoberman

Copy link
Copy Markdown
Contributor Author

Thanks Jack Oberman (Jack Oberman (@jackoberman)) ! I think the functionality is solid, I just have a few suggestions to improve readability / organization. Let me know if anything's not clear.

Andreas Albert (@AndreasAlbertQC) Thanks for the suggestions! I apologize it took me so long to respond.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jack Oberman (@jackoberman) ! Only super minor adjustments that I will just apply and then we are ready to go

Comment thread docs/guides/features/sql-generation.md Outdated
Comment thread tests/columns/test_sqlalchemy_columns.py
Comment thread tests/columns/test_sqlalchemy_columns.py
Comment thread dataframely/columns/enum.py Outdated
Co-authored-by: Andreas Albert <103571926+AndreasAlbertQC@users.noreply.github.com>
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (13d9fe2) to head (ad71405).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #355   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           56        56           
  Lines         3463      3471    +8     
=========================================
+ Hits          3463      3471    +8     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread docs/guides/features/sql-generation.md Outdated
Comment thread dataframely/columns/enum.py Outdated
Comment thread dataframely/columns/enum.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread docs/guides/features/sql-generation.md
Comment thread dataframely/columns/enum.py Outdated
@AndreasAlbertQC

Copy link
Copy Markdown
Collaborator

Jack Oberman (@jackoberman) while playing with this, I realized (thanks copilot :)) that the pattern of storing the private _enum_class member clashes with our implementations of matches etc on the column base class. We usually assume that a column is fully defined by the input arguments its constructor receives (with a few excluded ones like alias). You had introduced this private member so that you could get the default sqlalchemy names in case the user passes an enum. I now changed this such that we override sqlalchemy_enum_name manually in the constructor in this case, which really simplifies the implementation. Of course, that means that if sqlalchemy were to ever change the way it generates the default name, our implementation would differ from that. Personally, I think that that is a tolerable risk given the tradeoffs involved.

Please take a look and let me know what you think :)

Comment thread dataframely/columns/enum.py
Comment thread dataframely/columns/enum.py
@jackoberman

Copy link
Copy Markdown
Contributor Author

Jack Oberman (Jack Oberman (@jackoberman)) while playing with this, I realized (thanks copilot :)) that the pattern of storing the private _enum_class member clashes with our implementations of matches etc on the column base class. We usually assume that a column is fully defined by the input arguments its constructor receives (with a few excluded ones like alias). You had introduced this private member so that you could get the default sqlalchemy names in case the user passes an enum. I now changed this such that we override sqlalchemy_enum_name manually in the constructor in this case, which really simplifies the implementation. Of course, that means that if sqlalchemy were to ever change the way it generates the default name, our implementation would differ from that. Personally, I think that that is a tolerable risk given the tradeoffs involved.

Please take a look and let me know what you think :)

This is much cleaner! Very nice!

@jackoberman Jack Oberman (jackoberman) force-pushed the feat/enum-sqlalchemy-use-enum branch from 31a5b9e to ad71405 Compare July 1, 2026 15:14

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndreasAlbertQC Andreas Albert (AndreasAlbertQC) merged commit 3089ece into Quantco:main Jul 1, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Optional native SQLAlchemy Enum for dy.Enum in to_sqlalchemy_columns (Postgres)

3 participants