Skip to content

Commit

Permalink
group_by() to use use_shortnames + args fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mezantrop committed Sep 24, 2024
1 parent c1dda62 commit aa6bed7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# CHANGELOG

* **2024.09.24 Current - tSQLike-1.1.5 (candidate)**
* `group_by()` respects `use_shortnames`; `group_by()` to handle case with no `ftarget` or `function` arguments
* `order_by()` respects `use_shortnames`
* `join_lt()` respects `use_shortnames` for both Tables
* make `_make_shortnames()` method public
Expand Down
24 changes: 17 additions & 7 deletions tsqlike/tsqlike.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,19 +845,29 @@ def order_by(self, column='', direction=ORDER_BY_INC, new_tname='', **kwargs):
for c in range(self.cols)] for r in sl])

# -------------------------------------------------------------------------------------------- #
def group_by(self, column='', function=None, ftarget=None, new_tname=''):
def group_by(self, column='', function=None, ftarget=None, new_tname='', **kwargs):

"""
GROUP BY primitive of SQL SELECT
:param column: Group by this column
:param function: Aggregate function to apply
:param ftarget: Column to apply aggregate function
:param new_tname: Give a new name for the returned Table
:return: A new Table object
:param column: Group by this column
:param function: Aggregate function to apply
:param ftarget: Column to apply aggregate function
:param new_tname: Give a new name for the returned Table
:param **kwargs:
:param use_shortnames if True, Column names in Table header do not contain Table name
:return: A new Table object
"""

gd = {r[self.header.index(column)]: function(r[self.header.index(ftarget)])
if not ftarget or not function:
return Table(self)

header = self.header
if kwargs.get('use_shortnames', self.use_shortnames):
header = self.make_shortnames()


gd = {r[header.index(column)]: function(r[header.index(ftarget)])
for r in self.table}

return Table(name=new_tname if new_tname else
Expand Down

0 comments on commit aa6bed7

Please sign in to comment.