From 7f3791fc06d503f98ab294be9e78f50f4ffe6e39 Mon Sep 17 00:00:00 2001 From: akrherz Date: Mon, 22 Jan 2024 12:01:06 -0600 Subject: [PATCH] mnt: address some pandas2.2 warnings --- cgi-bin/request/daily.py | 2 +- cgi-bin/request/feel.py | 4 ++-- cgi-bin/request/gis/lsr.py | 2 +- cgi-bin/request/gis/watchwarn.py | 2 +- cgi-bin/request/hads.py | 2 +- cgi-bin/request/isusm.py | 4 +++- cgi-bin/request/mos.py | 2 +- cgi-bin/request/rwis.py | 2 +- cgi-bin/request/taf.py | 2 +- cgi-bin/request/talltowers.py | 2 +- cgi-bin/request/tempwind_aloft.py | 2 +- deployment/mod_wsgi_startup.py | 3 +++ environment.yml | 4 ++-- 13 files changed, 19 insertions(+), 14 deletions(-) diff --git a/cgi-bin/request/daily.py b/cgi-bin/request/daily.py index f7f2517924..f2c131e9a4 100644 --- a/cgi-bin/request/daily.py +++ b/cgi-bin/request/daily.py @@ -116,7 +116,7 @@ def get_data(network, sts, ets, stations, cols, na, fmt): if fmt == "excel": bio = BytesIO() with pd.ExcelWriter(bio, engine="xlsxwriter") as writer: - df.to_excel(writer, "Data", index=False) + df.to_excel(writer, sheet_name="Data", index=False) return bio.getvalue() sio = StringIO() diff --git a/cgi-bin/request/feel.py b/cgi-bin/request/feel.py index 944f99441c..77f5825b9b 100644 --- a/cgi-bin/request/feel.py +++ b/cgi-bin/request/feel.py @@ -35,8 +35,8 @@ def fmt(val): bio = BytesIO() with pd.ExcelWriter(bio, engine="openpyxl") as writer: - df.to_excel(writer, "Daily Data", index=False) - df2.to_excel(writer, "Hourly Data", index=False) + df.to_excel(writer, sheet_name="Daily Data", index=False) + df2.to_excel(writer, sheet_name="Hourly Data", index=False) headers = [ ("Content-type", EXL), diff --git a/cgi-bin/request/gis/lsr.py b/cgi-bin/request/gis/lsr.py index dd8f39e7b4..ee40a8983a 100644 --- a/cgi-bin/request/gis/lsr.py +++ b/cgi-bin/request/gis/lsr.py @@ -82,7 +82,7 @@ def do_excel_kml(fmt, sts, ets, wfolimiter, statelimiter): bio = BytesIO() # pylint: disable=abstract-class-instantiated writer = pd.ExcelWriter(bio, engine="xlsxwriter") - df.to_excel(writer, "Local Storm Reports", index=False) + df.to_excel(writer, sheet_name="Local Storm Reports", index=False) worksheet = writer.sheets["Local Storm Reports"] worksheet.set_column("B:C", 36) worksheet.set_column("D:E", 24) diff --git a/cgi-bin/request/gis/watchwarn.py b/cgi-bin/request/gis/watchwarn.py index da3cb38c3c..85afb7645b 100644 --- a/cgi-bin/request/gis/watchwarn.py +++ b/cgi-bin/request/gis/watchwarn.py @@ -207,7 +207,7 @@ def do_excel(sql): bio = BytesIO() # pylint: disable=abstract-class-instantiated with pd.ExcelWriter(bio, engine="xlsxwriter") as writer: - df.to_excel(writer, "VTEC WaWA", index=False) + df.to_excel(writer, sheet_name="VTEC WaWA", index=False) return bio.getvalue() diff --git a/cgi-bin/request/hads.py b/cgi-bin/request/hads.py index 5e5e42ad5f..81249ffa77 100644 --- a/cgi-bin/request/hads.py +++ b/cgi-bin/request/hads.py @@ -128,7 +128,7 @@ def application(environ, start_response): if what == "excel": bio = BytesIO() with pd.ExcelWriter(bio, engine="openpyxl") as writer: - table.to_excel(writer, "Data", index=True) + table.to_excel(writer, sheet_name="Data", index=True) headers = [ ("Content-type", EXL), diff --git a/cgi-bin/request/isusm.py b/cgi-bin/request/isusm.py index 1ae80a310e..611c5c033e 100644 --- a/cgi-bin/request/isusm.py +++ b/cgi-bin/request/isusm.py @@ -380,7 +380,9 @@ def application(environ, start_response): # pylint: disable=abstract-class-instantiated if cols: with pd.ExcelWriter(bio, engine="xlsxwriter") as writer: - df.to_excel(writer, "Data", columns=cols, index=False) + df.to_excel( + writer, sheet_name="Data", columns=cols, index=False + ) headers = [ ("Content-type", EXL), ("Content-disposition", "attachment; Filename=isusm.xlsx"), diff --git a/cgi-bin/request/mos.py b/cgi-bin/request/mos.py index 2e3576000c..71da123b29 100644 --- a/cgi-bin/request/mos.py +++ b/cgi-bin/request/mos.py @@ -50,7 +50,7 @@ def get_data(sts, ets, station, model, fmt): bio = BytesIO() # pylint: disable=abstract-class-instantiated with pd.ExcelWriter(bio, engine="xlsxwriter") as writer: - df.to_excel(writer, "Data", index=False) + df.to_excel(writer, sheet_name="Data", index=False) return bio.getvalue() sio = StringIO() diff --git a/cgi-bin/request/rwis.py b/cgi-bin/request/rwis.py index 3163ca3246..d2e83ec857 100644 --- a/cgi-bin/request/rwis.py +++ b/cgi-bin/request/rwis.py @@ -85,7 +85,7 @@ def get_lon(station): return [b"Dataset too large for excel format."] bio = BytesIO() with pd.ExcelWriter(bio) as writer: - df.to_excel(writer, "Data", index=False, columns=myvars) + df.to_excel(writer, sheet_name="Data", index=False, columns=myvars) headers = [ ("Content-type", EXL), diff --git a/cgi-bin/request/taf.py b/cgi-bin/request/taf.py index 3f51fce36d..880a6f3a95 100644 --- a/cgi-bin/request/taf.py +++ b/cgi-bin/request/taf.py @@ -46,7 +46,7 @@ def run(start_response, ctx): bio = BytesIO() if ctx["fmt"] == "excel": with pd.ExcelWriter(bio, engine="openpyxl") as writer: - df.to_excel(writer, "TAF Data", index=False) + df.to_excel(writer, sheet_name="TAF Data", index=False) headers = [ ("Content-type", EXL), ("Content-disposition", "attachment;Filename=taf.xlsx"), diff --git a/cgi-bin/request/talltowers.py b/cgi-bin/request/talltowers.py index 6fe31bba0b..ef035bde34 100644 --- a/cgi-bin/request/talltowers.py +++ b/cgi-bin/request/talltowers.py @@ -120,7 +120,7 @@ def application(environ, start_response): bio = BytesIO() # pylint: disable=abstract-class-instantiated with pd.ExcelWriter(bio, engine="xlsxwriter") as writer: - df.to_excel(writer, "Data", index=False) + df.to_excel(writer, sheet_name="Data", index=False) headers = [ ("Content-type", EXL), ("Content-disposition", "attachment; Filename=talltowers.xlsx"), diff --git a/cgi-bin/request/tempwind_aloft.py b/cgi-bin/request/tempwind_aloft.py index f6cadb535a..73f6b4fedc 100644 --- a/cgi-bin/request/tempwind_aloft.py +++ b/cgi-bin/request/tempwind_aloft.py @@ -43,7 +43,7 @@ def get_data(station, sts, ets, tz, na, fmt): if fmt == "excel": bio = BytesIO() with pd.ExcelWriter(bio, engine="xlsxwriter") as writer: - df.to_excel(writer, "Data", index=False) + df.to_excel(writer, sheet_name="Data", index=False) return bio.getvalue() sio = StringIO() diff --git a/deployment/mod_wsgi_startup.py b/deployment/mod_wsgi_startup.py index c7e80139d7..28146d6ff0 100644 --- a/deployment/mod_wsgi_startup.py +++ b/deployment/mod_wsgi_startup.py @@ -33,6 +33,9 @@ def warn_with_traceback( ) +# pandas 2.2 warning with fillna +pd.set_option("future.no_silent_downcasting", True) + warnings.showwarning = warn_with_traceback # Stop pandas UserWarning for now in prod if os.path.exists("/etc/IEMDEV"): diff --git a/environment.yml b/environment.yml index 8d5695c550..e3c6b7fba1 100644 --- a/environment.yml +++ b/environment.yml @@ -36,8 +36,8 @@ dependencies: - odfpy # excel output - openpyxl - # yo - - pandas + # due to config settings + - pandas>=2.2 # mod-wsgi - paste # PIL