From d6a4e7c24d0e09365730a607e85024af6c726897 Mon Sep 17 00:00:00 2001 From: tatianag Date: Thu, 5 Dec 2024 17:09:44 -0800 Subject: [PATCH] DM-47976: Support conversion field in file template format strings --- doc/changes/DM-47976.bugfix.md | 1 + python/lsst/daf/butler/datastore/file_templates.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 doc/changes/DM-47976.bugfix.md diff --git a/doc/changes/DM-47976.bugfix.md b/doc/changes/DM-47976.bugfix.md new file mode 100644 index 0000000000..1c427373a8 --- /dev/null +++ b/doc/changes/DM-47976.bugfix.md @@ -0,0 +1 @@ +Support type conversion field in file template format strings. diff --git a/python/lsst/daf/butler/datastore/file_templates.py b/python/lsst/daf/butler/datastore/file_templates.py index 85cbc8d93a..5496bdf952 100644 --- a/python/lsst/daf/butler/datastore/file_templates.py +++ b/python/lsst/daf/butler/datastore/file_templates.py @@ -571,7 +571,7 @@ def format(self, ref: DatasetRef) -> str: parts = fmt.parse(self.template) output = "" - for literal, field_name, format_spec, _ in parts: + for literal, field_name, format_spec, conversion in parts: if field_name and "|" in field_name: alternates = field_name.split("|") for alt in alternates: @@ -678,6 +678,10 @@ def format(self, ref: DatasetRef) -> str: if replace_slash: value = value.replace("/", "_") + # Apply conversion (e.g., integer to string) + if conversion: + value = fmt.convert_field(value, conversion) + # Now use standard formatting output = output + literal + format(value, format_spec)