Skip to content

Commit 3cd6ab9

Browse files
authored
Merge pull request #1215 from wright-group/create_constant
create_constant kwargs
2 parents 61aa859 + 4060c2c commit 3cd6ab9

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
77

88
## Changed
99
- local version identifier uses only ASCII letters/numbers and periods (PEP 440)
10+
- `Data.create_constant`: allow kwargs to be passed to the constant creation
1011

1112
## [3.6.0]
1213

WrightTools/data/_data.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,7 @@ def set_constants(self, *constants, verbose=True):
22632263
self.flush()
22642264
self._on_constants_updated()
22652265

2266-
def create_constant(self, expression, *, verbose=True):
2266+
def create_constant(self, expression, verbose=True, **kwargs):
22672267
"""Append a constant to the stored list.
22682268
22692269
Parameters
@@ -2272,6 +2272,8 @@ def create_constant(self, expression, *, verbose=True):
22722272
Expression for the new constant.
22732273
verbose : boolean (optional)
22742274
Toggle talkback. Default is True
2275+
**kwargs
2276+
extra kwargs are passed to `Constant.__init__`
22752277
22762278
See Also
22772279
--------
@@ -2283,7 +2285,7 @@ def create_constant(self, expression, *, verbose=True):
22832285
if expression in self.constant_expressions:
22842286
wt_exceptions.ObjectExistsWarning.warn(expression)
22852287
return self.constants[self.constant_expressions.index(expression)]
2286-
constant = Constant(self, expression)
2288+
constant = Constant(self, expression, **kwargs)
22872289
if constant.units is None:
22882290
constant.convert(constant.variables[0].units)
22892291
self._constants.append(constant)

tests/data/constants.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ def test_set_remove():
1818
assert data.constant_names == ()
1919

2020

21+
def test_units():
22+
"""smokescreen to make sure units can be specified for constant creation"""
23+
data = wt.Data()
24+
data.create_variable("y", np.ones((3,)), units="ps")
25+
data.create_constant("y", units="wn")
26+
27+
2128
def test_label():
2229
data = wt.Data()
2330
data.create_variable("x", np.linspace(0, 10))

0 commit comments

Comments
 (0)