Skip to content

Commit

Permalink
Set stacklevel
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonHeybrock committed Dec 7, 2023
1 parent 958ef5b commit f574ba9
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
# See https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length
max-line-length = 88
extend-ignore = E203, B028
extend-ignore = E203
3 changes: 2 additions & 1 deletion src/scippnexus/_hdf5_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def _warn_latin1_decode(obj, decoded, error):
f"extended ASCII (latin-1), but this behavior is not "
f"specified by the HDF5 or nexus standards and may therefore "
f"be incorrect. Decoded string using latin-1 is '{decoded}'. "
f"Error was '{error}'."
f"Error was '{error}'.",
stacklevel=2,
)


Expand Down
2 changes: 1 addition & 1 deletion src/scippnexus/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def _warn_fallback(self, e: Exception) -> None:
f"Failed to load {self.name} as {type(self._nexus).__name__}: {e} "
"Falling back to loading HDF5 group children as scipp.DataGroup."
)
warnings.warn(msg)
warnings.warn(msg, stacklevel=2)

def __setitem__(self, key, value):
"""Set a child group or child dataset.
Expand Down
3 changes: 2 additions & 1 deletion src/scippnexus/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ def unit(self) -> Union[sc.Unit, None]:
except sc.UnitError:
warnings.warn(
f"Unrecognized unit '{unit}' for value dataset "
f"in '{self.name}'; setting unit as 'dimensionless'"
f"in '{self.name}'; setting unit as 'dimensionless'",
stacklevel=2,
)
return sc.units.one
return None
3 changes: 2 additions & 1 deletion src/scippnexus/nxtransformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ def _with_positions(
out[store_transform] = transform
except TransformationChainResolver.ChainError as e:
warnings.warn(
UserWarning(f'depends_on chain references missing node:\n{e}')
UserWarning(f'depends_on chain references missing node:\n{e}'),
stacklevel=2,
)
for name, value in dg.items():
if isinstance(value, sc.DataGroup):
Expand Down
1 change: 1 addition & 0 deletions src/scippnexus/v1/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self, *args, definition=None, **kwargs):
"The scippnexus.v1 API is deprecated and will be removed in release 24.01. "
"Switch to 'import scippnexus as snx' to use API version 2.",
VisibleDeprecationWarning,
stacklevel=2,
)
self._file = h5py.File(*args, **kwargs)
NXroot.__init__(self, self._file, definition=definition)
Expand Down
10 changes: 6 additions & 4 deletions src/scippnexus/v1/nxobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ def unit(self) -> Union[sc.Unit, None]:
except sc.UnitError:
warnings.warn(
f"Unrecognized unit '{unit}' for value dataset "
f"in '{self.name}'; setting unit as 'dimensionless'"
f"in '{self.name}'; setting unit as 'dimensionless'",
stacklevel=2,
)
return sc.units.one
return None
Expand Down Expand Up @@ -389,7 +390,7 @@ def _get_child(
f"Failed to determine axis names of {item.name}: {e}. "
"Falling back to default dimension labels."
)
warnings.warn(msg)
warnings.warn(msg, stacklevel=2)
dims = None
dtype = self._get_field_dtype(name)
return Field(
Expand All @@ -415,7 +416,7 @@ def _get_child(
f"Failed to load {self.name} as {type(self).__name__}: {e} "
"Falling back to loading HDF5 group children as scipp.DataGroup."
)
warnings.warn(msg)
warnings.warn(msg, stacklevel=2)
da = NXobject._getitem(self, name)
return da

Expand Down Expand Up @@ -582,7 +583,8 @@ def depends_on(self) -> Union[sc.Variable, sc.DataArray, None]:
except (NexusStructureError, TransformationError) as e:
warnings.warn(
f"Failed to load transformation {self.name}/{depends_on}:\n{e}\n"
"Falling back to returning the path to the transformation."
"Falling back to returning the path to the transformation.",
stacklevel=2,
)
return depends_on[()]
return None
Expand Down

0 comments on commit f574ba9

Please sign in to comment.