Skip to content

Commit

Permalink
join_lt() - back to list concept
Browse files Browse the repository at this point in the history
  • Loading branch information
mezantrop committed Jul 5, 2024
1 parent 4d364a9 commit f546f19
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions tsqlike/tsqlike.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,6 @@ def join_lt(self, table, scol, tcol, mode=JOIN_INNER, new_tname='', replace=Fals

"""
Light, limited and safe Join, that doesn't use eval()
:param table: Table to join self with
:param scol: Self column to join on
:param tcol: Table column to join on
Expand All @@ -552,21 +551,19 @@ def join_lt(self, table, scol, tcol, mode=JOIN_INNER, new_tname='', replace=Fals

lci = self.header.index(scol) if scol in self.header else None
rci = table.header.index(tcol) if tcol in table.header else None
r_table = {}
r_table = []
tl_match = []
tr_match = []

# Concatenate table headers as row[0] of the results table
r_table[0] = self.header + table.header
r_table.append(self.header + table.header)

rtc = 0
if None not in (lci, rci):
# Inner JOIN
for tl in range(self.rows):
for tr in range(table.rows):
if self.table[tl][lci] == table.table[tr][rci]:
rtc += 1
r_table[rtc] = [*self.table[tl], *table.table[tr]]
r_table.append([*self.table[tl], *table.table[tr]])
if mode in (JOIN_LEFT, JOIN_FULL):
tl_match.append([*self.table[tl]])
tr_match.append([*table.table[tr]])
Expand All @@ -579,8 +576,6 @@ def join_lt(self, table, scol, tcol, mode=JOIN_INNER, new_tname='', replace=Fals
if it not in tr_match:
r_table.append([[None] * self.cols + table.table[it]])

r_table = list(r_table.keys())

if replace:
# Replace source - self - with the joined Table
return Table.import_list_lists(self, name=new_tname if new_tname else
Expand Down

0 comments on commit f546f19

Please sign in to comment.