Skip to content

Commit b30cc7e

Browse files
committed
maintain input_xtype, while make it non-settable
1 parent 8431fe2 commit b30cc7e

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/diffpy/utils/diffraction_objects.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ def all_arrays(self, _):
198198
raise AttributeError(_setter_wmsg("all_arrays"))
199199

200200
@property
201-
def xtype(self):
202-
return self._xtype
201+
def input_xtype(self):
202+
return self._input_xtype
203203

204-
@xtype.setter
205-
def xtype(self, _):
206-
raise AttributeError(_setter_wmsg("xtype"))
204+
@input_xtype.setter
205+
def input_xtype(self, _):
206+
raise AttributeError(_setter_wmsg("input_xtype"))
207207

208208
def set_angles_from_list(self, angles_list):
209209
self.angles = angles_list
@@ -289,7 +289,7 @@ def get_array_index(self, value, xtype=None):
289289
"""
290290

291291
if xtype is None:
292-
xtype = self._xtype
292+
xtype = self._input_xtype
293293
array = self.on_xtype(xtype)[0]
294294
if len(array) == 0:
295295
raise ValueError(f"The '{xtype}' array is empty. Please ensure it is initialized.")
@@ -348,7 +348,7 @@ def insert_scattering_quantity(
348348
"""
349349
self._set_xarrays(xarray, xtype)
350350
self._all_arrays[:, 0] = yarray
351-
self._xtype = xtype
351+
self._input_xtype = xtype
352352
# only update these optional values if non-empty quantities are passed to avoid overwriting
353353
# valid data inadvertently
354354
if metadata:

tests/test_diffraction_objects.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def test_dump(tmp_path, mocker):
286286
{
287287
"_all_arrays": np.empty(shape=(0, 4)), # instantiate empty
288288
"metadata": {},
289-
"_xtype": "",
289+
"_input_xtype": "",
290290
"name": "",
291291
"scat_quantity": None,
292292
"qmin": np.float64(np.inf),
@@ -303,7 +303,7 @@ def test_dump(tmp_path, mocker):
303303
{
304304
"_all_arrays": np.empty(shape=(0, 4)),
305305
"metadata": {"thing": "1", "another": "2"},
306-
"_xtype": "",
306+
"_input_xtype": "",
307307
"name": "test",
308308
"scat_quantity": "x-ray",
309309
"qmin": np.float64(np.inf),
@@ -331,7 +331,7 @@ def test_dump(tmp_path, mocker):
331331
]
332332
),
333333
"metadata": {},
334-
"_xtype": "tth",
334+
"_input_xtype": "tth",
335335
"name": "",
336336
"scat_quantity": None,
337337
"qmin": np.float64(0.0),
@@ -360,7 +360,7 @@ def test_dump(tmp_path, mocker):
360360
]
361361
),
362362
"metadata": {},
363-
"_xtype": "d",
363+
"_input_xtype": "d",
364364
"name": "",
365365
"scat_quantity": "x-ray",
366366
"qmin": np.float64(0.0),
@@ -411,21 +411,21 @@ def test_all_array_setter():
411411
actual_do.all_arrays = np.empty((4, 4))
412412

413413

414-
def test_xtype_getter():
414+
def test_input_xtype_getter():
415415
do = DiffractionObject(xtype="tth")
416-
assert do.xtype == "tth"
416+
assert do.input_xtype == "tth"
417417

418418

419-
def test_xtype_setter():
419+
def test_input_xtype_setter():
420420
do = DiffractionObject(xtype="tth")
421421

422422
# Attempt to directly modify the property
423423
with pytest.raises(
424424
AttributeError,
425-
match="Direct modification of attribute 'xtype' is not allowed."
426-
"Please use 'insert_scattering_quantity' to modify 'xtype'.",
425+
match="Direct modification of attribute 'input_xtype' is not allowed."
426+
"Please use 'insert_scattering_quantity' to modify 'input_xtype'.",
427427
):
428-
do.xtype = "q"
428+
do.input_xtype = "q"
429429

430430

431431
def test_copy_object():

0 commit comments

Comments
 (0)