Skip to content

Commit 18728a4

Browse files
committed
Document relation between equality testing and difference utilities.
1 parent e4524d6 commit 18728a4

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

docs/userdocs/user_guide/common_operations.rst

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,20 @@ There is also a utility function :func:`ncdata.utils.ncdata_copy` : This is
118118
effectively the same thing as the NcData object :meth:`~ncdata.NcData.copy` method.
119119

120120

121-
Equality Checking
122-
-----------------
123-
We provide a simple, comprehensive ``==`` check for :mod:`~ncdata.NcDimension` and
124-
:mod:`~ncdata.NcAttribute` objects, but not at present :mod:`~ncdata.NcVariable` or
125-
:mod:`~ncdata.NcData`.
126-
127-
So, using ``==`` on :mod:`~ncdata.NcVariable` or :mod:`~ncdata.NcData` objects
128-
will only do an identity check -- that is, it tests ``id(A) == id(B)``, or ``A is B``.
129-
130-
However, these objects **can** be properly compared with the dataset comparison
131-
utilities, :func:`ncdata.utils.dataset_differences` and
132-
:func:`ncdata.utils.variable_differences`. By default, these operations are very
133-
comprehensive and may be very costly for instance comparing large data arrays, but they
134-
also allow more nuanced and controllable checking, e.g. to skip data array comparisons
135-
or ignore variable ordering.
121+
Equality Testing
122+
----------------
123+
We implement equality operations ``==`` / ``!=`` for all the core data objects.
124+
125+
However, simple equality testing on :class:`@ncdata.NcData` and :class:`@ncdata.NcVariable`
126+
objects can be very costly if it requires comparing large data arrays.
127+
128+
If you need to avoid comparing large (and possibly lazy) arrays then you can use the
129+
:func:`ncdata.utils.dataset_differences` and
130+
:func:`ncdata.utils.variable_differences` utility functions.
131+
These functions also provide multiple options to enable more tolerant comparison,
132+
such as allowing variables to have a different ordering.
133+
134+
See: :ref:`utils_equality`
136135

137136
.. _object_creation:
138137

@@ -187,8 +186,7 @@ The result is the same:
187186

188187
.. doctest:: python
189188

190-
>>> from ncdata.utils import dataset_differences
191-
>>> print(dataset_differences(data1, data2))
192-
[]
189+
>>> data1 == data2
190+
True
193191

194192

docs/userdocs/user_guide/utilities.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Rename Dimensions
99
The :func:`~ncdata.utils.rename_dimension` utility does this, in a way which ensures a
1010
safe and consistent result.
1111

12+
.. _utils_equality:
13+
1214
Dataset Equality Testing
1315
------------------------
1416
The function :func:`~ncdata.utils.dataset_differences` produces a list of messages
@@ -50,9 +52,11 @@ For Example:
5052
:func:`~ncdata.utils.variable_differences` is also provided.
5153

5254
.. note::
53-
The :meth:`ncdata.NcData.__eq__` and :meth:`ncdata.NcVariable.__eq__` comparison
54-
methods are based on these utility functions. This makes the basic ``==`` operation
55-
potentially very expensive, if large arrays are involved.
55+
The ``==`` and ``!-`` operations on :class:`ncdata.NcData` and
56+
:class:`ncdata.NcVariable` are implemented to call these utility functions.
57+
However, lacking a keyword interface to enable any tolerance options, the operations
58+
compare absolutely everything, and so can be very performance intensive if large data
59+
arrays are present.
5660

5761
.. _indexing_overview:
5862

0 commit comments

Comments
 (0)