Skip to content

v2.1.1 - #89

Merged
zaihuaji merged 1 commit into
mainfrom
hua-work-common
Mar 19, 2026
Merged

zaihuaji merged 1 commit into
mainfrom
hua-work-common

Conversation

@zaihuaji

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings March 19, 2026 21:03

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

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.1 in pyproject.toml.
  • Move PostgreSQL timestamp formatting helpers (fmtyr, fmtqt, etc.) from class attributes into PgDBI.__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.

Comment on lines +28 to +33
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)

Copilot AI Mar 19, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
Comment on lines 24 to +34
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)

Copilot AI Mar 19, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines +27 to +33
# 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)

Copilot AI Mar 19, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@zaihuaji
zaihuaji merged commit f9c59c7 into main Mar 19, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants