Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

define_unit override argument #239

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions unyt/unit_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ def _validate_dimensions(dimensions):


def define_unit(
symbol, value, tex_repr=None, offset=None, prefixable=False, registry=None
symbol, value, tex_repr=None, offset=None, prefixable=False, registry=None, override=False
):
"""
Define a new unit and add it to the specified unit registry.
Expand All @@ -1064,6 +1064,9 @@ def define_unit(
unit object will be added as an attribute to the top-level :mod:`unyt`
namespace to ease working with the newly defined unit. See the example
below.
override : boolean, optional
Whether or not to allow an override to an existing unit in the given
unit registry.

Examples
--------
Expand All @@ -1080,7 +1083,7 @@ def define_unit(

if registry is None:
registry = default_unit_registry
if symbol in registry:
if symbol in registry and not override:
raise RuntimeError(
"Unit symbol '%s' already exists in the provided " "registry" % symbol
)
Expand Down