Configuration#
unxt.config controls how quantities render in repr() and str(). It is a traitlets Configurable with two nested sections:
Object |
Class |
Controls |
|---|---|---|
|
|
|
|
|
|
Each section holds the same four options with different defaults. For how to set them, see How to control how quantities are displayed.
>>> import unxt as u
Options#
Option |
Type |
|
|
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
short_arrays#
How the value is rendered.
Value |
Rendering |
|---|---|
|
full array repr โ |
|
shape and dtype summary โ |
|
values without the |
>>> q = u.Q([1.0, 2.0, 3.0], "m")
>>> with u.config.quantity_repr.override(short_arrays=False):
... print(repr(q))
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> with u.config.quantity_repr.override(short_arrays=True):
... print(repr(q))
Quantity(f32[3], unit='m')
>>> with u.config.quantity_repr.override(short_arrays="compact"):
... print(repr(q))
Quantity([1., 2., 3.], unit='m')
use_short_name#
When True, a class renders under its short name where it has one โ Quantity becomes Q.
>>> q1 = u.Q(1.0, "m")
>>> with u.config.quantity_repr.override(use_short_name=False):
... print(repr(q1))
Quantity(Array(1., dtype=float32...), unit='m')
>>> with u.config.quantity_repr.override(use_short_name=True):
... print(repr(q1))
Q(Array(1., dtype=float32...), unit='m')
named_unit#
When True, the unit renders as the keyword unit='m'; when False, positionally as 'm'.
>>> with u.config.quantity_repr.override(named_unit=False):
... print(repr(q1))
Quantity(Array(1., dtype=float32...), 'm')
>>> with u.config.quantity_repr.override(named_unit=True):
... print(repr(q1))
Quantity(Array(1., dtype=float32...), unit='m')
indent#
Indentation width, in spaces, for nested structures.
>>> print(repr(u.Q([[1.0, 2.0], [3.0, 4.0]], "m"))) # default: 4
Quantity(Array([[1., 2.],
[3., 4.]], dtype=float32), unit='m')
str() defaults#
quantity_str differs from quantity_repr only in the default for short_arrays, which is "compact":
>>> print(str(q))
Quantity([1., 2., 3.], unit='m')
>>> with u.config.quantity_str.override(short_arrays=False):
... print(str(q))
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> with u.config.quantity_str.override(short_arrays=True):
... print(str(q))
Quantity(f32[3], unit='m')
>>> with u.config.quantity_str.override(named_unit=False):
... print(str(q1))
Quantity(1., 'm')
>>> with u.config.quantity_str.override(use_short_name=True):
... print(str(q1))
Q(1., unit='m')
pyproject.toml keys#
unxt reads the nearest pyproject.toml once, at import, searching upward from Path.cwd(). Only the keys present in the file are applied; every other setting keeps its default.
Section |
Applies to |
|---|---|
|
|
|
|
[tool.unxts.unxt.quantity.repr]
short_arrays = "compact"
use_short_name = true
named_unit = false
indent = 4
[tool.unxts.unxt.quantity.str]
short_arrays = true
named_unit = false
use_short_name = false
indent = 4
The loaded configuration applies globally for the active Python process.
Warning
The section was named [tool.unxt...] before v2. A leftover [tool.unxt] section is ignored, and unxt emits a DeprecationWarning at import. See How to migrate to v2.
API#
Member |
Signature |
Returns |
|---|---|---|
|
|
context manager |
|
|
context manager |
|
|
|
|
|
|
Overrides are thread-local: each thread keeps its own independent override stack.
See also#
How to control how quantities are displayed โ recipes for setting these.
Quantity โ the classes whose display these control.