Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Dont set replace=True as this removes all formatting
Browse files Browse the repository at this point in the history
Formatting for portal_run_id must be set to 'TEXT' for number format
  • Loading branch information
alexiswl committed May 8, 2024
1 parent 987cce6 commit 5e04c47
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
9 changes: 9 additions & 0 deletions deploy/cttso-ica-to-pieriandx-cdk/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
Changes in this log refer only to changes that make it to the 'main' branch and
are nested under deploy/cttso-ica-to-pieriandx-cdk.

## 2024-05-08

> Author: Alexis Lucattini
> Email: [[email protected]](mailto:[email protected])
### Hotfixes

* Excel interprets a few portal run ids as numbers i.e 2021121980805e78

## 2024-05-07

> Author: Alexis Lucattini
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,33 @@ def append_df_to_cttso_lims(new_df: pd.DataFrame, replace=False):
new_df = new_df.replace({pd.NaT: None}).replace({'NaT': None}).replace({np.NaN: ""})

if replace:
# Add an extra 1000 rows to the bottom of the page
# We have to resize the sheet, rather than reset/replace
# Since the replace method also removes the formats
sheet_obj.sheet.resize(1, 1)
# Add the header
sheet_obj.df_to_sheet(pd.DataFrame(data=None, columns=new_df.columns), index=False)
# Reformat the sheet so that the portal_run_id is interpreted as a string
sheet_obj.sheet.format("P", {"numberFormat": {"type": "TEXT"}})
# Update the sheet with the data
sheet_obj.df_to_sheet(
pd.concat(
[
new_df,
pd.DataFrame(columns=new_df.columns, index=range(1000))
]
),
index=False, replace=True, fill_value=""
index=False, replace=False, fill_value=""
)
else:
# Get existing sheet
existing_sheet = sheet_obj.sheet_to_df(index=0)
# We have to resize the sheet, rather than reset/replace
# Since the replace method also removes the formats
sheet_obj.sheet.resize(1, 1)
# Add the header
sheet_obj.df_to_sheet(pd.DataFrame(data=None, columns=new_df.columns), index=False)
# Reformat the sheet so that the portal_run_id is interpreted as a string
sheet_obj.sheet.format("P", {"numberFormat": {"type": "TEXT"}})
# Update the sheet object with the list
sheet_obj.df_to_sheet(
pd.concat(
Expand All @@ -185,7 +199,7 @@ def append_df_to_cttso_lims(new_df: pd.DataFrame, replace=False):
pd.DataFrame(columns=existing_sheet.columns, index=range(1000))
]
),
index=False, replace=True, fill_value=""
index=False, replace=False, fill_value=""
)


Expand Down Expand Up @@ -353,6 +367,12 @@ def append_rows_to_deleted_lims(to_be_deleted: pd.DataFrame):

# Get existing sheet
existing_sheet = sheet_obj.sheet_to_df(index=0)
# Since the replace method also removes the formats
sheet_obj.sheet.resize(1, 1)
# Add the header
sheet_obj.df_to_sheet(pd.DataFrame(data=None, columns=existing_sheet.columns), index=False)
# Reformat the sheet so that the portal_run_id is interpreted as a string
sheet_obj.sheet.format("P", {"numberFormat": {"type": "TEXT"}})
# Update the sheet object with the list
sheet_obj.df_to_sheet(
pd.concat(
Expand All @@ -362,7 +382,7 @@ def append_rows_to_deleted_lims(to_be_deleted: pd.DataFrame):
pd.DataFrame(columns=existing_sheet.columns, index=range(1000))
]
),
index=False, replace=True, fill_value=""
index=False, replace=False, fill_value=""
)


Expand Down

0 comments on commit 5e04c47

Please sign in to comment.