Skip to content

Commit 1a2214f

Browse files
committed
Rename id to uuid in DiffractionObjet
1 parent 8107874 commit 1a2214f

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

news/uuid-rename.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* DiffractionObject's "id" property renamed to "uuid"
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

src/diffpy/utils/diffraction_objects.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class DiffractionObject:
5050
The array containing the quantity of q, tth, d values.
5151
input_xtype : str
5252
The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES}
53-
id : uuid
53+
_uuid : uuid
5454
The unique identifier for the diffraction object.
5555
scat_quantity : str
5656
The type of scattering experiment (e.g., "x-ray", "neutron"). Default is an empty string "".
@@ -127,7 +127,7 @@ def __init__(
127127
>>> print(do.metadata)
128128
"""
129129

130-
self._id = uuid.uuid4()
130+
self._uuid = uuid.uuid4()
131131
self._input_data(xarray, yarray, xtype, wavelength, scat_quantity, name, metadata)
132132

133133
def _input_data(self, xarray, yarray, xtype, wavelength, scat_quantity, name, metadata):
@@ -299,12 +299,12 @@ def input_xtype(self, _):
299299
raise AttributeError(_setter_wmsg("input_xtype"))
300300

301301
@property
302-
def id(self):
303-
return self._id
302+
def uuid(self):
303+
return self._uuid
304304

305-
@id.setter
306-
def id(self, _):
307-
raise AttributeError(_setter_wmsg("id"))
305+
@uuid.setter
306+
def uuid(self, _):
307+
raise AttributeError(_setter_wmsg("uuid"))
308308

309309
def get_array_index(self, value, xtype=None):
310310
"""Return the index of the closest value in the array associated with

tests/test_diffraction_objects.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def test_init_valid(do_init_args, expected_do_dict, divide_by_zero_warning_expec
479479
else:
480480
actual_do_dict = DiffractionObject(**do_init_args).__dict__
481481
diff = DeepDiff(
482-
actual_do_dict, expected_do_dict, ignore_order=True, significant_digits=13, exclude_paths="root['_id']"
482+
actual_do_dict, expected_do_dict, ignore_order=True, significant_digits=13, exclude_paths="root['_uuid']"
483483
)
484484
assert diff == {}
485485

@@ -523,27 +523,29 @@ def test_all_array_setter(do_minimal):
523523
do.all_arrays = np.empty((4, 4))
524524

525525

526-
def test_id_getter(do_minimal):
526+
def test_uuid_getter(do_minimal):
527527
do = do_minimal
528-
assert hasattr(do, "id")
529-
assert isinstance(do.id, UUID)
530-
assert len(str(do.id)) == 36
528+
assert hasattr(do, "uuid")
529+
assert isinstance(do.uuid, UUID)
530+
assert len(str(do.uuid)) == 36
531531

532532

533-
def test_id_getter_with_mock(mocker, do_minimal):
534-
mocker.patch.object(DiffractionObject, "id", new_callable=lambda: UUID("d67b19c6-3016-439f-81f7-cf20a04bee87"))
533+
def test_uuid_getter_with_mock(mocker, do_minimal):
534+
mocker.patch.object(
535+
DiffractionObject, "uuid", new_callable=lambda: UUID("d67b19c6-3016-439f-81f7-cf20a04bee87")
536+
)
535537
do = do_minimal
536-
assert do.id == UUID("d67b19c6-3016-439f-81f7-cf20a04bee87")
538+
assert do.uuid == UUID("d67b19c6-3016-439f-81f7-cf20a04bee87")
537539

538540

539-
def test_id_setter_error(do_minimal):
541+
def test_uuid_setter_error(do_minimal):
540542
do = do_minimal
541543

542544
with pytest.raises(
543545
AttributeError,
544-
match="Direct modification of attribute 'id' is not allowed. Please use 'input_data' to modify 'id'.",
546+
match="Direct modification of attribute 'uuid' is not allowed. Please use 'input_data' to modify 'uuid'.",
545547
):
546-
do.id = uuid.uuid4()
548+
do.uuid = uuid.uuid4()
547549

548550

549551
def test_xarray_yarray_length_mismatch():

0 commit comments

Comments
 (0)