v2.1.1 - #89
v2.1.1#89
Conversation
There was a problem hiding this comment.
Pull request overview
This PR prepares the v2.1.1 release by updating the package version and adjusting how PostgreSQL timestamp formatting helpers are exposed on PgDBI.
Changes:
- Bump package version to
2.1.1inpyproject.toml. - Move PostgreSQL timestamp formatting helpers (
fmtyr,fmtqt, etc.) from class attributes intoPgDBI.__init__.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/rda_python_common/pg_dbi.py |
Changes where timestamp SQL formatter helpers are defined/exposed on PgDBI. |
pyproject.toml |
Updates project version to 2.1.1. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| self.fmtyr = lambda fn=self: "extract(year from {})::int".format(fn) | ||
| self.fmtqt = lambda fn=self: "extract(quarter from {})::int".format(fn) | ||
| self.fmtmn = lambda fn=self: "extract(month from {})::int".format(fn) | ||
| self.fmtdt = lambda fn=self: "date({})".format(fn) | ||
| self.fmtym = lambda fn=self: "to_char({}, 'yyyy-mm')".format(fn) | ||
| self.fmthr = lambda fn=self: "extract(hour from {})::int".format(fn) |
There was a problem hiding this comment.
The default argument fn=self captures the instance in the lambda’s __defaults__, creating an unnecessary self-reference cycle and making self.fmtyr() (no args) format the PgDBI object instead of a field/expression. These formatters don’t need self; define them without a self default (e.g., require fn), or better, make them @staticmethods to avoid capturing the instance at all.
| self.fmtyr = lambda fn=self: "extract(year from {})::int".format(fn) | |
| self.fmtqt = lambda fn=self: "extract(quarter from {})::int".format(fn) | |
| self.fmtmn = lambda fn=self: "extract(month from {})::int".format(fn) | |
| self.fmtdt = lambda fn=self: "date({})".format(fn) | |
| self.fmtym = lambda fn=self: "to_char({}, 'yyyy-mm')".format(fn) | |
| self.fmthr = lambda fn=self: "extract(hour from {})::int".format(fn) | |
| self.fmtyr = lambda fn: "extract(year from {})::int".format(fn) | |
| self.fmtqt = lambda fn: "extract(quarter from {})::int".format(fn) | |
| self.fmtmn = lambda fn: "extract(month from {})::int".format(fn) | |
| self.fmtdt = lambda fn: "date({})".format(fn) | |
| self.fmtym = lambda fn: "to_char({}, 'yyyy-mm')".format(fn) | |
| self.fmthr = lambda fn: "extract(hour from {})::int".format(fn) |
| def __init__(self): | ||
| super().__init__() # initialize parent class | ||
|
|
||
| # PostgreSQL specified query timestamp format | ||
| self.fmtyr = lambda fn=self: "extract(year from {})::int".format(fn) | ||
| self.fmtqt = lambda fn=self: "extract(quarter from {})::int".format(fn) | ||
| self.fmtmn = lambda fn=self: "extract(month from {})::int".format(fn) | ||
| self.fmtdt = lambda fn=self: "date({})".format(fn) | ||
| self.fmtym = lambda fn=self: "to_char({}, 'yyyy-mm')".format(fn) | ||
| self.fmthr = lambda fn=self: "extract(hour from {})::int".format(fn) | ||
|
|
There was a problem hiding this comment.
These timestamp format helpers used to be available on the class (e.g., PgDBI.fmtyr('col')); moving them into __init__ makes that usage fail because the attributes won’t exist until an instance is created. If external callers may rely on class-level access, consider keeping them as class attributes but mark them as @staticmethod/staticmethod(...) so they work from both the class and instances without method binding issues.
| def __init__(self): | |
| super().__init__() # initialize parent class | |
| # PostgreSQL specified query timestamp format | |
| self.fmtyr = lambda fn=self: "extract(year from {})::int".format(fn) | |
| self.fmtqt = lambda fn=self: "extract(quarter from {})::int".format(fn) | |
| self.fmtmn = lambda fn=self: "extract(month from {})::int".format(fn) | |
| self.fmtdt = lambda fn=self: "date({})".format(fn) | |
| self.fmtym = lambda fn=self: "to_char({}, 'yyyy-mm')".format(fn) | |
| self.fmthr = lambda fn=self: "extract(hour from {})::int".format(fn) | |
| # PostgreSQL specified query timestamp format | |
| @staticmethod | |
| def fmtyr(fn): | |
| return "extract(year from {})::int".format(fn) | |
| @staticmethod | |
| def fmtqt(fn): | |
| return "extract(quarter from {})::int".format(fn) | |
| @staticmethod | |
| def fmtmn(fn): | |
| return "extract(month from {})::int".format(fn) | |
| @staticmethod | |
| def fmtdt(fn): | |
| return "date({})".format(fn) | |
| @staticmethod | |
| def fmtym(fn): | |
| return "to_char({}, 'yyyy-mm')".format(fn) | |
| @staticmethod | |
| def fmthr(fn): | |
| return "extract(hour from {})::int".format(fn) | |
| def __init__(self): | |
| super().__init__() # initialize parent class |
| # PostgreSQL specified query timestamp format | ||
| self.fmtyr = lambda fn=self: "extract(year from {})::int".format(fn) | ||
| self.fmtqt = lambda fn=self: "extract(quarter from {})::int".format(fn) | ||
| self.fmtmn = lambda fn=self: "extract(month from {})::int".format(fn) | ||
| self.fmtdt = lambda fn=self: "date({})".format(fn) | ||
| self.fmtym = lambda fn=self: "to_char({}, 'yyyy-mm')".format(fn) | ||
| self.fmthr = lambda fn=self: "extract(hour from {})::int".format(fn) |
There was a problem hiding this comment.
The behavior of these SQL timestamp formatter helpers is changing, but there are no tests asserting their outputs or verifying they can be called from an instance/class as intended. Adding a small pytest unit test for PgDBI().fmtyr/fmtqt/... (and, if supported, PgDBI.fmtyr/...) would help prevent regressions in query generation.
No description provided.