darcymason: Just noticed that since only values are compared, it is possible to pass even if some of the tags are different but have same value (very unlikely, but could happen if many entries were empty string, for example).

Would be nice to add a test too, e.g. the example from the issue first comment.

I'm not sure deriving from OrderedDict is worth it, there are only a few places where ordering is needed.
mrbean-bremen: Ok, you are probably right - it doesn't make much sense then.
scaramallion: `Dataset.values()` returns a list of `DataElement` so different tags with the same value will return False since `DataElement` equality checks tag, VR and value.

I already added a test reproducing #462 as my first commit, unless you're referring to something else?
darcymason: You're right of course, my bad, just looking too quickly
diff --git a/pydicom/dataset.py b/pydicom/dataset.py
index 69b68f7ef..6e0f82daf 100644
--- a/pydicom/dataset.py
+++ b/pydicom/dataset.py
@@ -400,8 +400,10 @@ class Dataset(dict):
             # __dict__
             # Convert values() to a list for compatibility between
             #   python 2 and 3
-            return (list(self.values()) == list(other.values()) and
-                    self.__dict__ == other.__dict__)
+            # Sort values() by element tag
+            self_elem = sorted(list(self.values()), key=lambda x: x.tag)
+            other_elem = sorted(list(other.values()), key=lambda x: x.tag)
+            return self_elem == other_elem and self.__dict__ == other.__dict__
 
         return NotImplemented
 

Dataset equality fails when elements added in different order
#### Description
Dataset equality produces incorrect results

#### Steps/Code to Reproduce
```python
>>> from pydicom.dataset import Dataset
>>> ds = Dataset()
>>> ds.PatientName = 'Test'
>>> ds.PatientID = '1234'
>>> ds2 = Dataset()
>>> ds2.PatientID = '1234'
>>> ds2.PatientName = 'Test
>>> ds == ds2
False
>>> ds2 = Dataset()
>>> ds2.PatientName = 'Test'
>>> ds2.PatientID = '1234'
>>> ds == ds2
True
```

#### Versions
```python
>>> import platform; print(platform.platform())
Linux-4.10.0-30-generic-x86_64-with-Ubuntu-17.04-zesty
>>> import sys; print("Python", sys.version)
Python 3.6.1 (default, Mar 22 2017, 06:17:05) 
[GCC 6.3.0 20170321]
>>> import pydicom; print("pydicom", pydicom.__version__)
pydicom 1.0.0a1
```
diff --git a/pydicom/tests/test_dataset.py b/pydicom/tests/test_dataset.py
index 01dfa0453..f25160446 100644
--- a/pydicom/tests/test_dataset.py
+++ b/pydicom/tests/test_dataset.py
@@ -401,9 +401,11 @@ class DatasetTests(unittest.TestCase):
         """Dataset: equality returns correct value with simple dataset"""
         d = Dataset()
         d.SOPInstanceUID = '1.2.3.4'
+        d.PatientName = 'Test'
         self.assertTrue(d == d)
 
         e = Dataset()
+        e.PatientName = 'Test'
         e.SOPInstanceUID = '1.2.3.4'
         self.assertTrue(d == e)
 
@@ -457,6 +459,7 @@ class DatasetTests(unittest.TestCase):
         d.SOPInstanceUID = '1.2.3.4'
         d.BeamSequence = []
         beam_seq = Dataset()
+        beam_seq.PatientID = '1234'
         beam_seq.PatientName = 'ANON'
         d.BeamSequence.append(beam_seq)
         self.assertTrue(d == d)
@@ -466,6 +469,7 @@ class DatasetTests(unittest.TestCase):
         e.BeamSequence = []
         beam_seq = Dataset()
         beam_seq.PatientName = 'ANON'
+        beam_seq.PatientID = '1234'
         e.BeamSequence.append(beam_seq)
         self.assertTrue(d == e)
 

pip install -e .
parse_log_pytest
pytest
pytest
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
certifi==2021.5.30
importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1631916693255/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
-e git+https://github.com/pydicom/pydicom.git@affb1cf10c6be2aca311c29ddddc622f8bd1f810#egg=pydicom
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: pydicom
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib-metadata=4.8.1=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
prefix: /opt/conda/envs/pydicom

pydicom/tests/test_dataset.py::DatasetTests::testEqualityNoSequence pydicom/tests/test_dataset.py::DatasetTests::testEqualitySequence
pydicom/tests/test_dataset.py::DatasetTests::test_get_item
pydicom/tests/test_dataset.py::DatasetTests::testAttributeErrorInProperty pydicom/tests/test_dataset.py::DatasetTests::testDeleteDicomAttr pydicom/tests/test_dataset.py::DatasetTests::testDeleteDicomAttrWeDontHave pydicom/tests/test_dataset.py::DatasetTests::testDeleteDicomCommandGroupLength pydicom/tests/test_dataset.py::DatasetTests::testDeleteItemLong pydicom/tests/test_dataset.py::DatasetTests::testDeleteItemTuple pydicom/tests/test_dataset.py::DatasetTests::testDeleteNonExistingItem pydicom/tests/test_dataset.py::DatasetTests::testDeleteOtherAttr pydicom/tests/test_dataset.py::DatasetTests::testEqualityInheritance pydicom/tests/test_dataset.py::DatasetTests::testEqualityNotDataset pydicom/tests/test_dataset.py::DatasetTests::testEqualityPrivate pydicom/tests/test_dataset.py::DatasetTests::testEqualityUnknown pydicom/tests/test_dataset.py::DatasetTests::testGetDefault1 pydicom/tests/test_dataset.py::DatasetTests::testGetDefault2 pydicom/tests/test_dataset.py::DatasetTests::testGetDefault3 pydicom/tests/test_dataset.py::DatasetTests::testGetDefault4 pydicom/tests/test_dataset.py::DatasetTests::testGetExists1 pydicom/tests/test_dataset.py::DatasetTests::testGetExists2 pydicom/tests/test_dataset.py::DatasetTests::testGetExists3 pydicom/tests/test_dataset.py::DatasetTests::testGetExists4 pydicom/tests/test_dataset.py::DatasetTests::testGetFromRaw pydicom/tests/test_dataset.py::DatasetTests::testHash pydicom/tests/test_dataset.py::DatasetTests::testMembership pydicom/tests/test_dataset.py::DatasetTests::testSetExistingDataElementByName pydicom/tests/test_dataset.py::DatasetTests::testSetNewDataElementByName pydicom/tests/test_dataset.py::DatasetTests::testSetNonDicom pydicom/tests/test_dataset.py::DatasetTests::testTagExceptionPrint pydicom/tests/test_dataset.py::DatasetTests::testTagExceptionWalk pydicom/tests/test_dataset.py::DatasetTests::testUpdate pydicom/tests/test_dataset.py::DatasetTests::test_NamedMemberUpdated pydicom/tests/test_dataset.py::DatasetTests::test__setitem__ pydicom/tests/test_dataset.py::DatasetTests::test_add_repeater_elem_by_keyword pydicom/tests/test_dataset.py::DatasetTests::test_attribute_error_in_property_correct_debug pydicom/tests/test_dataset.py::DatasetTests::test_contains pydicom/tests/test_dataset.py::DatasetTests::test_data_element pydicom/tests/test_dataset.py::DatasetTests::test_delitem_slice pydicom/tests/test_dataset.py::DatasetTests::test_dir pydicom/tests/test_dataset.py::DatasetTests::test_dir_filter pydicom/tests/test_dataset.py::DatasetTests::test_empty_slice pydicom/tests/test_dataset.py::DatasetTests::test_exit_exception pydicom/tests/test_dataset.py::DatasetTests::test_formatted_lines pydicom/tests/test_dataset.py::DatasetTests::test_get_pixel_array_already_have pydicom/tests/test_dataset.py::DatasetTests::test_get_raises pydicom/tests/test_dataset.py::DatasetTests::test_getitem_slice pydicom/tests/test_dataset.py::DatasetTests::test_getitem_slice_raises pydicom/tests/test_dataset.py::DatasetTests::test_group_dataset pydicom/tests/test_dataset.py::DatasetTests::test_inequality pydicom/tests/test_dataset.py::DatasetTests::test_is_uncompressed_transfer_syntax pydicom/tests/test_dataset.py::DatasetTests::test_iterall pydicom/tests/test_dataset.py::DatasetTests::test_matching_tags pydicom/tests/test_dataset.py::DatasetTests::test_property pydicom/tests/test_dataset.py::DatasetTests::test_remove_private_tags pydicom/tests/test_dataset.py::DatasetTests::test_reshape_pixel_array_not_implemented pydicom/tests/test_dataset.py::DatasetTests::test_save_as pydicom/tests/test_dataset.py::DatasetTests::test_set_convert_private_elem_from_raw pydicom/tests/test_dataset.py::DatasetTests::test_setitem_slice_raises pydicom/tests/test_dataset.py::DatasetTests::test_top pydicom/tests/test_dataset.py::DatasetTests::test_trait_names pydicom/tests/test_dataset.py::DatasetTests::test_walk pydicom/tests/test_dataset.py::DatasetTests::test_with pydicom/tests/test_dataset.py::DatasetElementsTests::testSequenceAssignment pydicom/tests/test_dataset.py::FileDatasetTests::test_creation_with_container pydicom/tests/test_dataset.py::FileDatasetTests::test_equality_file_meta
pydicom/dataset.py
pydicom/dataset.py