Skip to content

Commit 204842b

Browse files
committed
refs #281, Flatfile fixes
Small fixes to Flatfile driver to work with pandas
1 parent 2030c32 commit 204842b

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

examples/Flatfile_examples/csv_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import PySimpleGUI as sg
66
import logging
77
logger=logging.getLogger(__name__)
8-
logging.basicConfig(level=logging.INFO)
8+
logging.basicConfig(level=logging.DEBUG)
99

1010
# Let's use a fun language pack
1111
ss.languagepack(ss.lp_90s)
@@ -36,7 +36,7 @@
3636
driver = ss.Driver.flatfile('test.csv', header_row_num=10)
3737

3838
# Use a pysimplesql Form to bind the window to the driver
39-
frm= ss.Form(driver, bind_window=win)
39+
frm = ss.Form(driver, bind_window=win)
4040

4141
# This is optional. Forces the saving of unchanged records. This will allow us to use our sortable headers to arrange
4242
# the data to our liking, then hit save without making any actual changes to the data and have the newly sorted

examples/SQLite_examples/Journal.db

0 Bytes
Binary file not shown.

pysimplesql/pysimplesql.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,6 @@ def requery(
10371037
# Strip trailing white space, as this is what sg[element].get() does, so we
10381038
# can have an equal comparison. Not the prettiest solution. Will look into
10391039
# this more on the PySimpleGUI end and make a follow-up ticket.
1040-
10411040
# TODO: Is the [:,:] still needed now that we are working with DateFrames?
10421041
self.rows.loc[:, :] = self.rows.applymap(
10431042
lambda x: x.rstrip() if isinstance(x, str) else x
@@ -1586,7 +1585,6 @@ def save_record(
15861585
:returns: SAVE_NONE, SAVE_FAIL or SAVE_SUCCESS masked with SHOW_MESSAGE
15871586
"""
15881587
logger.debug(f"Saving records for table {self.table}...")
1589-
15901588
if display_message is None:
15911589
display_message = not self.save_quiet
15921590

@@ -6919,7 +6917,7 @@ def save_record(
69196917

69206918
# Update the DataSet object's DataFra,e with the changes, so then
69216919
# the entire DataFrame can be written back to file sequentially
6922-
dataset.rows[dataset.current_index] = changed_row
6920+
dataset.rows.iloc[dataset.current_index] = pd.Series(changed_row)
69236921

69246922
# open the CSV file for writing
69256923
with open(self.file_path, "w", newline="\n") as csvfile:
@@ -6932,15 +6930,14 @@ def save_record(
69326930
# Write out the stored pre_header lines
69336931
for line in self.pre_header:
69346932
writer.writerow(line)
6935-
69366933
# write the header row
69376934
writer.writerow(list(self.columns))
69386935

69396936
# write the DataFrame out.
69406937
# Use our columns to exclude the possible virtual pk
69416938
rows = []
6942-
for r in dataset.rows:
6943-
rows.append([r[c] for c in self.columns])
6939+
for index, row in dataset.rows.iterrows():
6940+
rows.append([row[c] for c in self.columns])
69446941

69456942
logger.debug(f"Writing the following data to {self.file_path}")
69466943
logger.debug(rows)

0 commit comments

Comments
 (0)