diff --git a/news/uuid-rename.rst b/news/uuid-rename.rst new file mode 100644 index 00000000..ecd7f22d --- /dev/null +++ b/news/uuid-rename.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* DiffractionObject's "id" property renamed to "uuid" + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/src/diffpy/utils/diffraction_objects.py b/src/diffpy/utils/diffraction_objects.py index 92ad17dc..6118f46d 100644 --- a/src/diffpy/utils/diffraction_objects.py +++ b/src/diffpy/utils/diffraction_objects.py @@ -46,12 +46,6 @@ class DiffractionObject: Attributes ---------- - all_arrays : ndarray - The array containing the quantity of q, tth, d values. - input_xtype : str - The type of the independent variable in `xarray`. Must be one of {*XQUANTITIES} - id : uuid - The unique identifier for the diffraction object. scat_quantity : str The type of scattering experiment (e.g., "x-ray", "neutron"). Default is an empty string "". wavelength : float @@ -127,7 +121,7 @@ def __init__( >>> print(do.metadata) """ - self._id = uuid.uuid4() + self._uuid = uuid.uuid4() self._input_data(xarray, yarray, xtype, wavelength, scat_quantity, name, metadata) def _input_data(self, xarray, yarray, xtype, wavelength, scat_quantity, name, metadata): @@ -284,6 +278,23 @@ def __rtruediv__(self, other): @property def all_arrays(self): + """The 2D array containing `xarray` and `yarray` values. + + Returns + ------- + ndarray + The shape (len(data), 4) 2D array with columns containing the `yarray` (intensity) + and the `xarray` values in q, tth, and d. + + Examples + -------- + To access specific arrays individually, use these slices: + + >>> my_do.all_arrays[:, 0] # yarray + >>> my_do.all_arrays[:, 1] # xarray in q + >>> my_do.all_arrays[:, 2] # xarray in tth + >>> my_do.all_arrays[:, 3] # xarray in d + """ return self._all_arrays @all_arrays.setter @@ -292,6 +303,13 @@ def all_arrays(self, _): @property def input_xtype(self): + """The type of the independent variable in `xarray`. + + Returns + ------- + str + The type of `xarray`, which must be one of {*XQUANTITIES}. + """ return self._input_xtype @input_xtype.setter @@ -299,12 +317,19 @@ def input_xtype(self, _): raise AttributeError(_setter_wmsg("input_xtype")) @property - def id(self): - return self._id + def uuid(self): + """The unique identifier for the DiffractionObject instance. + + Returns + ------- + uuid + The unique identifier of the DiffractionObject instance. + """ + return self._uuid - @id.setter - def id(self, _): - raise AttributeError(_setter_wmsg("id")) + @uuid.setter + def uuid(self, _): + raise AttributeError(_setter_wmsg("uuid")) def get_array_index(self, value, xtype=None): """Return the index of the closest value in the array associated with @@ -319,7 +344,8 @@ def get_array_index(self, value, xtype=None): Returns ------- - the index of the value in the array + list + The list containing the index of the closest value in the array. """ xtype = self._input_xtype diff --git a/tests/test_diffraction_objects.py b/tests/test_diffraction_objects.py index 63f349eb..33675b9e 100644 --- a/tests/test_diffraction_objects.py +++ b/tests/test_diffraction_objects.py @@ -479,7 +479,7 @@ def test_init_valid(do_init_args, expected_do_dict, divide_by_zero_warning_expec else: actual_do_dict = DiffractionObject(**do_init_args).__dict__ diff = DeepDiff( - actual_do_dict, expected_do_dict, ignore_order=True, significant_digits=13, exclude_paths="root['_id']" + actual_do_dict, expected_do_dict, ignore_order=True, significant_digits=13, exclude_paths="root['_uuid']" ) assert diff == {} @@ -523,27 +523,29 @@ def test_all_array_setter(do_minimal): do.all_arrays = np.empty((4, 4)) -def test_id_getter(do_minimal): +def test_uuid_getter(do_minimal): do = do_minimal - assert hasattr(do, "id") - assert isinstance(do.id, UUID) - assert len(str(do.id)) == 36 + assert hasattr(do, "uuid") + assert isinstance(do.uuid, UUID) + assert len(str(do.uuid)) == 36 -def test_id_getter_with_mock(mocker, do_minimal): - mocker.patch.object(DiffractionObject, "id", new_callable=lambda: UUID("d67b19c6-3016-439f-81f7-cf20a04bee87")) +def test_uuid_getter_with_mock(mocker, do_minimal): + mocker.patch.object( + DiffractionObject, "uuid", new_callable=lambda: UUID("d67b19c6-3016-439f-81f7-cf20a04bee87") + ) do = do_minimal - assert do.id == UUID("d67b19c6-3016-439f-81f7-cf20a04bee87") + assert do.uuid == UUID("d67b19c6-3016-439f-81f7-cf20a04bee87") -def test_id_setter_error(do_minimal): +def test_uuid_setter_error(do_minimal): do = do_minimal with pytest.raises( AttributeError, - match="Direct modification of attribute 'id' is not allowed. Please use 'input_data' to modify 'id'.", + match="Direct modification of attribute 'uuid' is not allowed. Please use 'input_data' to modify 'uuid'.", ): - do.id = uuid.uuid4() + do.uuid = uuid.uuid4() def test_xarray_yarray_length_mismatch():