From 7c9b344cd7b375bb13bd650c1f4dbdfaba6b031a Mon Sep 17 00:00:00 2001 From: Paul McLeod <47012528+IvanKaramazov@users.noreply.github.com> Date: Wed, 14 Aug 2024 16:48:10 -0700 Subject: [PATCH] Silencing Pandas downcasting warning on df creation The latest version of Pandas throws an annoying warning in many cases when df.replace() is called. Adding a context manager to silence this per the warning instructions. --- gspread_pandas/spread.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/gspread_pandas/spread.py b/gspread_pandas/spread.py index 50f0046..ea3db40 100644 --- a/gspread_pandas/spread.py +++ b/gspread_pandas/spread.py @@ -396,12 +396,13 @@ def sheet_to_df( col_names = parse_sheet_headers(vals, header_rows) # remove rows where everything is null, then replace nulls with '' - df = ( - pd.DataFrame(vals[header_rows or 0 :]) - .replace("", np.nan) - .dropna(how="all") - .fillna("") - ) + with pd.option_context('future.no_silent_downcasting', True): + df = ( + pd.DataFrame(vals[header_rows or 0 :]) + .replace("", np.nan) + .dropna(how="all") + .fillna("") + ) # replace values with a different value render option before we set the # index in set_col_names