From de2e7fc70fc4447ad94037c1e30878498a7839fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20de=20Menten?= Date: Fri, 19 Dec 2025 16:22:10 +0100 Subject: [PATCH] FIX: fixed warning message stack level on Python < 3.12 --- larray/core/axis.py | 5 +++-- larray/core/group.py | 10 ++++------ larray/util/misc.py | 3 +++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/larray/core/axis.py b/larray/core/axis.py index 39c0c8236..ef4b0109b 100644 --- a/larray/core/axis.py +++ b/larray/core/axis.py @@ -17,7 +17,7 @@ from larray.util.misc import (duplicates, array_lookup2, ReprString, index_by_id, renamed_to, LHDFStore, lazy_attribute, _isnoneslice, unique_list, unique_multi, Product, argsort, has_duplicates, exactly_one, concatenate_ndarrays) -from larray.util.misc import first, find_names +from larray.util.misc import first, find_names, PY312_OR_LATER from larray.util.types import Scalar @@ -2921,7 +2921,8 @@ def _guess_axis(self, axis_key): # behavior, we must wait for a future release, and we # only output a warning for now (see #1117) # return axis_key.retarget_to(real_axis) - check_warn_retarget(axis_key, real_axis, stacklevel=8) + stack_level = 8 if PY312_OR_LATER else 9 + check_warn_retarget(axis_key, real_axis, stacklevel=stack_level) return axis_key.with_axis(real_axis) real_axis, axis_pos_key = self._translate_nice_key(axis_key) diff --git a/larray/core/group.py b/larray/core/group.py index 60c536040..c8c39ed27 100644 --- a/larray/core/group.py +++ b/larray/core/group.py @@ -1,5 +1,3 @@ -import sys - import fnmatch import re import warnings @@ -12,13 +10,13 @@ from larray.core.abstractbases import ABCAxis, ABCAxisReference, ABCArray from larray.util.oset import OrderedSet -from larray.util.misc import (unique_list, find_closing_chr, _parse_bound, _seq_summary, _isintstring, renamed_to, - LHDFStore) +from larray.util.misc import ( + unique_list, find_closing_chr, _parse_bound, _seq_summary, _isintstring, + renamed_to, LHDFStore, PY312_OR_LATER +) from larray.util.types import Scalar, Key -PY312_OR_LATER = sys.version_info[:2] >= (3, 12) - def _slice_to_str(key: slice, repr_func=str) -> str: r""" Convert a slice to a string. diff --git a/larray/util/misc.py b/larray/util/misc.py index e5354aafd..6b41fef99 100644 --- a/larray/util/misc.py +++ b/larray/util/misc.py @@ -1130,3 +1130,6 @@ def find_names(obj, depth=0): if any(not name.startswith('_') for name in names): names = [name for name in names if not name.startswith('_')] return sorted(names) + + +PY312_OR_LATER = sys.version_info[:2] >= (3, 12)