Skip to content

Commit f631f4d

Browse files
committed
Fix for when inserting row into empty dataframe.
1 parent f59ee58 commit f631f4d

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

pysimplesql/pysimplesql.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,9 @@ def requery(
998998
not len(self.frm[parent_table].rows.index)
999999
or Relationship.parent_virtual(self.table, self.frm)
10001000
):
1001-
self.rows = pd.DataFrame(columns=self.rows.columns) # purge rows
1001+
# purge rows
1002+
self.rows = Result.set(pd.DataFrame(columns=self.rows.columns))
1003+
10021004
if update_elements:
10031005
self.frm.update_elements(self.key)
10041006
if requery_dependents:
@@ -2369,13 +2371,22 @@ def insert_row(self, row: dict, idx: int = None) -> None:
23692371
:returns: None
23702372
"""
23712373
row_series = pd.Series(row)
2372-
attrs = self.rows.attrs.copy()
2373-
self.rows = pd.concat([self.rows, row_series.to_frame().T], ignore_index=True)
2374-
self.rows.attrs = attrs
2374+
if self.rows.empty:
2375+
self.rows = Result.set(
2376+
pd.concat([self.rows, row_series.to_frame().T], ignore_index=True)
2377+
)
2378+
else:
2379+
attrs = self.rows.attrs.copy()
2380+
2381+
# TODO: idx currently does nothing
2382+
if idx is None:
2383+
idx = len(self.rows.index)
2384+
2385+
self.rows = pd.concat(
2386+
[self.rows, row_series.to_frame().T], ignore_index=True
2387+
)
2388+
self.rows.attrs = attrs
23752389

2376-
# I don't have the idx parameter working yet
2377-
if idx is None:
2378-
idx = len(self.rows.index)
23792390
idx_label = self.rows.index.max() if len(self.rows.index) > 0 else 0
23802391
self.rows.attrs["virtual"].loc[idx_label] = 1 # True, series only holds int64
23812392

0 commit comments

Comments
 (0)