From 3bab5a9de1b755a05c6ce48b7e66d8650074c83c Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Tue, 20 Feb 2024 17:04:47 -0500 Subject: [PATCH 1/3] Use `datetime.timezone.utc` over `datetime.utcfromtimestamp` > The method "utcfromtimestamp" in class "datetime" is deprecated > Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .fromtimestamp(datetime.UTC) (reportDeprecated) --- shiny/input_handler.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shiny/input_handler.py b/shiny/input_handler.py index 5a45bba5c..ae08ffef1 100644 --- a/shiny/input_handler.py +++ b/shiny/input_handler.py @@ -4,7 +4,7 @@ __all__ = ("input_handlers",) -from datetime import date, datetime +from datetime import date, datetime, timezone from typing import TYPE_CHECKING, Any, Callable, Dict if TYPE_CHECKING: @@ -113,10 +113,10 @@ def _( value: int | float | list[int] | list[float], name: ResolvedId, session: Session ) -> datetime | tuple[datetime, datetime]: if isinstance(value, (int, float)): - return datetime.utcfromtimestamp(value) + return datetime.fromtimestamp(value, timezone.utc) return ( - datetime.utcfromtimestamp(value[0]), - datetime.utcfromtimestamp(value[1]), + datetime.fromtimestamp(value[0], timezone.utc), + datetime.fromtimestamp(value[1], timezone.utc), ) From dd9b04eb0ece35a8b2fee9e8154946e35772fa42 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Tue, 20 Feb 2024 17:07:33 -0500 Subject: [PATCH 2/3] Use `datetime.datetime.now(tz=datetime.timezone.utc)` over `datetime.datetime.utcnow()` > The method "utcnow" in class "datetime" is deprecated > Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .now(datetime.UTC) (reportDeprecated) --- tests/playwright/shiny/inputs/input_task_button/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/playwright/shiny/inputs/input_task_button/app.py b/tests/playwright/shiny/inputs/input_task_button/app.py index edd483f9e..b5feb7fb8 100644 --- a/tests/playwright/shiny/inputs/input_task_button/app.py +++ b/tests/playwright/shiny/inputs/input_task_button/app.py @@ -1,5 +1,5 @@ import asyncio -from datetime import datetime +from datetime import datetime, timezone from shiny import reactive, render from shiny.express import input, ui @@ -10,7 +10,7 @@ @render.text() def current_time() -> str: reactive.invalidate_later(0.1) - return str(datetime.now().utcnow()) + return str(datetime.now(timezone.utc).isoformat()) with ui.p(): From 3f28f4ad52112dd0343914aa378462405db0a5ed Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Tue, 20 Feb 2024 17:12:19 -0500 Subject: [PATCH 3/3] Changelog entry --- CHANGELOG.md | 1 + shiny/plotutils.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abe26c4a1..1eef6dfc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Other changes * Replaced use of `sys.stderr.write()` with `print(file=sys.stderr)`, because on some platforms `sys.stderr` can be `None`. (#1131) +* Replaced deprecated `datetime` method calls with `datetime.fromtimestamp(tz=timezone.utc)` and `datetime.now(timezone.utc)`. (#1142) ## [0.7.1] - 2024-02-05 diff --git a/shiny/plotutils.py b/shiny/plotutils.py index 340496473..85aebac8a 100644 --- a/shiny/plotutils.py +++ b/shiny/plotutils.py @@ -312,7 +312,7 @@ def near_points( if all_rows: # Add selected_ column if needed new_df["selected_"] = False - new_df.iloc[ + new_df.iloc[ # pyright: ignore[reportArgumentType] keep_idx, new_df.columns.get_loc( # pyright: ignore[reportUnknownMemberType] "selected_"