@@ -542,7 +542,7 @@ def __init__(
542
542
self .search_order : List [str ] = []
543
543
self .selector : List [str ] = []
544
544
self .callbacks : CallbacksDict = {}
545
- self .transform : Optional [Callable [[pd . DataFrame , int ], None ]] = None
545
+ self .transform : Optional [Callable [[ResultSet , int ], None ]] = None
546
546
self .filtered : bool = filtered
547
547
if prompt_save is None :
548
548
self ._prompt_save = self .frm ._prompt_save
@@ -825,7 +825,7 @@ def records_changed(self, column: str = None, recursive=True) -> bool:
825
825
826
826
# don't check if there aren't any rows. Fixes checkbox = '' when no
827
827
# rows.
828
- if not len (self .frm [mapped .table ].rows ):
828
+ if not len (self .frm [mapped .table ].rows . index ):
829
829
continue
830
830
831
831
# Get the element value and cast it, so we can compare it to the
@@ -836,7 +836,7 @@ def records_changed(self, column: str = None, recursive=True) -> bool:
836
836
# the appropriate table column.
837
837
table_val = None
838
838
if mapped .where_column is not None :
839
- for row in self .rows :
839
+ for index , row in self .rows . itterrows () :
840
840
if row [mapped .where_column ] == mapped .where_value :
841
841
table_val = row [mapped .column ]
842
842
else :
@@ -977,7 +977,7 @@ def requery(
977
977
# Stop requery short if parent has no records or current row is virtual
978
978
parent_table = Relationship .get_parent (self .table )
979
979
if parent_table and (
980
- not len (self .frm [parent_table ].rows )
980
+ not len (self .frm [parent_table ].rows . index )
981
981
or Relationship .parent_virtual (self .table , self .frm )
982
982
):
983
983
self .rows = ResultSet ([]) # purge rows
@@ -1003,7 +1003,6 @@ def requery(
1003
1003
# now we can restore the sort order
1004
1004
self .rows .load_sort_settings (sort_settings )
1005
1005
self .rows .sort (self .table )
1006
-
1007
1006
# Perform transform one row at a time
1008
1007
if self .transform is not None :
1009
1008
self .rows = self .rows .apply (
@@ -1013,7 +1012,10 @@ def requery(
1013
1012
# Strip trailing white space, as this is what sg[element].get() does, so we
1014
1013
# can have an equal comparison. Not the prettiest solution. Will look into
1015
1014
# this more on the PySimpleGUI end and make a follow-up ticket.
1016
- self .rows = self .rows .applymap (
1015
+
1016
+ # Note on the below. Without rows.loc[:,:], the .applymap would return an entirely new DataFrame, and not
1017
+ # a ResultSet. TODO: Move this into it's own ResultSet method?
1018
+ self .rows .loc [:, :] = self .rows .applymap (
1017
1019
lambda x : x .rstrip () if isinstance (x , str ) else x
1018
1020
)
1019
1021
@@ -1108,7 +1110,7 @@ def last(
1108
1110
# don't update self/dependents if we are going to below anyway
1109
1111
self .prompt_save (update_elements = False )
1110
1112
1111
- self .current_index = len (self .rows ) - 1
1113
+ self .current_index = len (self .rows . index ) - 1
1112
1114
if update_elements :
1113
1115
self .frm .update_elements (self .key )
1114
1116
if requery_dependents :
@@ -1137,7 +1139,7 @@ def next(
1137
1139
:param skip_prompt_save: (optional) True to skip prompting to save dirty records
1138
1140
:returns: None
1139
1141
"""
1140
- if self .current_index < len (self .rows ) - 1 :
1142
+ if self .current_index < len (self .rows . index ) - 1 :
1141
1143
logger .debug (f"Moving to the next record of table { self .table } " )
1142
1144
if skip_prompt_save is False :
1143
1145
# don't update self/dependents if we are going to below anyway
@@ -1237,12 +1239,12 @@ def search(
1237
1239
self .prompt_save (update_elements = False )
1238
1240
1239
1241
# First lets make a search order.. TODO: remove this hard coded garbage
1240
- if len (self .rows ):
1242
+ if len (self .rows . index ):
1241
1243
logger .debug (f"DEBUG: { self .search_order } { self .rows [0 ].keys ()} " )
1242
1244
for o in self .search_order :
1243
1245
# Perform a search for str, from the current position to the end and back by
1244
1246
# creating a list of all indexes
1245
- for i in list (range (self .current_index + 1 , len (self .rows ))) + list (
1247
+ for i in list (range (self .current_index + 1 , len (self .rows . index ))) + list (
1246
1248
range (0 , self .current_index )
1247
1249
):
1248
1250
if (
@@ -1415,7 +1417,7 @@ def get_keyed_value(
1415
1417
:param key_value: The value to search for
1416
1418
:returns: Returns the value found in `value_column`
1417
1419
"""
1418
- for r in self .rows :
1420
+ for i , r in self .rows . itterrows () :
1419
1421
if r [key_column ] == key_value :
1420
1422
return r [value_column ]
1421
1423
return None
@@ -1531,8 +1533,8 @@ def insert_record(
1531
1533
# Update the pk to match the expected pk the driver would generate on insert.
1532
1534
new_values [self .pk_column ] = self .driver .next_pk (self .table , self .pk_column )
1533
1535
1534
- # Insert the new values using RecordSet.insert (), marking the new row as virtual
1535
- self .rows .insert (new_values )
1536
+ # Insert the new values using ResultSet.insert_row (), marking the new row as virtual
1537
+ self .rows .insert_row (new_values )
1536
1538
1537
1539
# and move to the new record
1538
1540
self .set_by_pk (
@@ -3204,7 +3206,6 @@ def update_elements(
3204
3206
# Populate the combobox entries
3205
3207
else :
3206
3208
lst = []
3207
- print (type (target_table ), target_table )
3208
3209
for index , row in target_table .rows .iterrows ():
3209
3210
lst .append (ElementRow (row [pk_column ], row [description ]))
3210
3211
@@ -5876,7 +5877,7 @@ def __init__(
5876
5877
self .sort_reverse = False
5877
5878
self .attrs ["original_index" ] = self .index .copy () # Store the original index
5878
5879
self .attrs ["virtual" ] = pd .Series (
5879
- [False ] * len (self ), index = self .index
5880
+ [False ] * len (self ), index = self .index , dtype = bool
5880
5881
) # Store virtual flags for each row
5881
5882
5882
5883
def __str__ (self ):
@@ -5900,7 +5901,7 @@ def fetchall(self) -> ResultSet:
5900
5901
"""
5901
5902
return self
5902
5903
5903
- def insert (self , row : dict , idx : int = None , virtual : bool = False ) -> None :
5904
+ def insert_row (self , row : dict , idx : int = None ) -> None :
5904
5905
"""
5905
5906
Insert a new virtual row into the `ResultSet`. Virtual rows are ones that exist
5906
5907
in memory, but not in the database. When a save action is performed, virtual
@@ -5918,7 +5919,7 @@ def insert(self, row: dict, idx: int = None, virtual: bool = False) -> None:
5918
5919
self .attrs ["original_index" ] = self .attrs ["original_index" ].insert (
5919
5920
idx , idx_label
5920
5921
)
5921
- self .attrs ["virtual" ].loc [idx_label ] = virtual
5922
+ self .attrs ["virtual" ].loc [idx_label ] = True
5922
5923
self .sort_index ()
5923
5924
5924
5925
def purge_virtual (self ) -> None :
@@ -6659,7 +6660,7 @@ def execute(
6659
6660
silent = False ,
6660
6661
column_info = None ,
6661
6662
auto_commit_rollback : bool = False ,
6662
- ):
6663
+ ) -> ResultSet :
6663
6664
if not silent :
6664
6665
logger .info (f"Executing query: { query } { values } " )
6665
6666
0 commit comments