From 2b98aa148dcaef753cb64e55e3a8063f6b2e9410 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Fri, 28 Jul 2023 16:39:27 -0700 Subject: [PATCH 1/4] Issue warning from caller code Otherwise the warning comes from inside afw and the caller doesn't really know which line was causing the problem. --- python/lsst/afw/image/_exposureSummaryStats.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/lsst/afw/image/_exposureSummaryStats.py b/python/lsst/afw/image/_exposureSummaryStats.py index f20caeb36..5a9a31657 100644 --- a/python/lsst/afw/image/_exposureSummaryStats.py +++ b/python/lsst/afw/image/_exposureSummaryStats.py @@ -160,6 +160,7 @@ def _read(bytes): "Please use a newer stack." ), FutureWarning, + stacklevel=2, ) return ExposureSummaryStats(**yamlDict) From 8f4372b28fa1a4e54ca5e9235de91f6cc3149337 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Fri, 28 Jul 2023 16:43:13 -0700 Subject: [PATCH 2/4] Remove unnecessary parentheses around strings --- python/lsst/afw/image/_exposureSummaryStats.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/python/lsst/afw/image/_exposureSummaryStats.py b/python/lsst/afw/image/_exposureSummaryStats.py index 5a9a31657..b64898889 100644 --- a/python/lsst/afw/image/_exposureSummaryStats.py +++ b/python/lsst/afw/image/_exposureSummaryStats.py @@ -155,10 +155,7 @@ def _read(bytes): if len(droppedFields) > 0: droppedFieldString = ", ".join([str(f) for f in droppedFields]) warnings.warn( - ( - f"Could not read summary fields [{droppedFieldString}]. " - "Please use a newer stack." - ), + f"Could not read summary fields [{droppedFieldString}]. Please use a newer stack.", FutureWarning, stacklevel=2, ) From adac34d4d70ff24a5bedc74cbb332817253dabd0 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Wed, 2 Aug 2023 14:10:52 -0700 Subject: [PATCH 3/4] Rephrase message so as not to suggest updating the stack --- python/lsst/afw/image/_exposureSummaryStats.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/lsst/afw/image/_exposureSummaryStats.py b/python/lsst/afw/image/_exposureSummaryStats.py index b64898889..ee3b694cf 100644 --- a/python/lsst/afw/image/_exposureSummaryStats.py +++ b/python/lsst/afw/image/_exposureSummaryStats.py @@ -155,7 +155,8 @@ def _read(bytes): if len(droppedFields) > 0: droppedFieldString = ", ".join([str(f) for f in droppedFields]) warnings.warn( - f"Could not read summary fields [{droppedFieldString}]. Please use a newer stack.", + f"Summary fields [{droppedFieldString}] not recognized by this software version;" + " ignoring them.", FutureWarning, stacklevel=2, ) From effbe398ba3f78f604eda3837c9a03359a1577e3 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Wed, 2 Aug 2023 15:08:07 -0700 Subject: [PATCH 4/4] Use plural or singular in warning depending on count --- python/lsst/afw/image/_exposureSummaryStats.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/lsst/afw/image/_exposureSummaryStats.py b/python/lsst/afw/image/_exposureSummaryStats.py index ee3b694cf..a3fef6787 100644 --- a/python/lsst/afw/image/_exposureSummaryStats.py +++ b/python/lsst/afw/image/_exposureSummaryStats.py @@ -154,9 +154,11 @@ def _read(bytes): yamlDict.pop(_field) if len(droppedFields) > 0: droppedFieldString = ", ".join([str(f) for f in droppedFields]) + plural = "s" if len(droppedFields) != 1 else "" + them = "them" if len(droppedFields) > 1 else "it" warnings.warn( - f"Summary fields [{droppedFieldString}] not recognized by this software version;" - " ignoring them.", + f"Summary field{plural} [{droppedFieldString}] not recognized by this software version;" + f" ignoring {them}.", FutureWarning, stacklevel=2, )