From 5edf5baa0dcb12eb0c2233ce8256d06b53af4cd5 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Thu, 19 Mar 2026 15:18:12 +0100 Subject: [PATCH 1/3] Fix issue with new locals() in Python 3.13 --- hendrics/create_gti.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/hendrics/create_gti.py b/hendrics/create_gti.py index 027ada18..72077210 100644 --- a/hendrics/create_gti.py +++ b/hendrics/create_gti.py @@ -69,15 +69,16 @@ def create_gti(fname, filter_expr, safe_interval=[0, 0], outfile=None, minimum_l mjdref = data.mjdref # Map all entries of data to local variables array_attrs = data.array_attrs() + ["time"] - locals().update(zip(array_attrs, [getattr(data, attr) for attr in array_attrs])) if hasattr(data, "internal_array_attrs"): - array_attrs = data.internal_array_attrs() - mod_array_attrs = [attr.replace("_", "") for attr in array_attrs] - locals().update(zip(mod_array_attrs, [getattr(data, attr) for attr in array_attrs])) + new_array_attrs = data.internal_array_attrs() + mod_array_attrs = [attr.replace("_", "") for attr in new_array_attrs] + array_attrs += mod_array_attrs - good = eval(filter_expr) + new_locals = {attr: getattr(data, attr) for attr in array_attrs} - gti = create_gti_from_condition(locals()["time"], good, safe_interval=safe_interval) + good = eval(filter_expr, locals=new_locals) + + gti = create_gti_from_condition(new_locals["time"], good, safe_interval=safe_interval) gti = filter_gti_by_length(gti, minimum_length) From 11b426bc3b1def1a6eae7074988762abaeea93c2 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Thu, 19 Mar 2026 15:20:20 +0100 Subject: [PATCH 2/3] Add changelog --- docs/changes/195.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changes/195.bugfix.rst diff --git a/docs/changes/195.bugfix.rst b/docs/changes/195.bugfix.rst new file mode 100644 index 00000000..8807d4a0 --- /dev/null +++ b/docs/changes/195.bugfix.rst @@ -0,0 +1 @@ +Fix use of locals() which has changed behavior in Python 3.13 From 8d8f814b0053b88ee68553567f6ee462f23a317e Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Thu, 19 Mar 2026 15:30:20 +0100 Subject: [PATCH 3/3] Pass locals and globals as simple arguments. Should work in all allowed python versions --- hendrics/create_gti.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hendrics/create_gti.py b/hendrics/create_gti.py index 72077210..276acc09 100644 --- a/hendrics/create_gti.py +++ b/hendrics/create_gti.py @@ -76,7 +76,7 @@ def create_gti(fname, filter_expr, safe_interval=[0, 0], outfile=None, minimum_l new_locals = {attr: getattr(data, attr) for attr in array_attrs} - good = eval(filter_expr, locals=new_locals) + good = eval(filter_expr, None, new_locals) gti = create_gti_from_condition(new_locals["time"], good, safe_interval=safe_interval)