darcymason: I had a quick look at this and it looked fine, but then I tried commenting out the 'continue' lines to make the test fail, and got some strange warnings from values.py about unexpected length.

I've been travelling and haven't had a chance to try again or investigate further.  Will look into it when I can, or perhaps someone else can give it a try -- I may have set something up incorrectly.
mrbean-bremen: Hm, if I do the same (e.g. replace `continue` with `pass`) I get:
```
    def test_write_removes_grouplength(self):
        ds = dcmread(color_pl_name)
        assert 0x00080000 in ds
        ds.save_as(self.file_out, write_like_original=True)
        self.file_out.seek(0)
        ds = dcmread(self.file_out)
        # group length has been removed
>       assert 0x00080000 not in ds
E       AssertionError: assert 524288 not in (0008, 0000) Group Length                        UL: 480\n(0008, 0008) Image Type                          CS: ['ORIGIN...Group Length                        UL: 92172\n(7fe0, 0010) Pixel Data                          OW: Array of 92160 bytes
```
which looks ok to me.
darcymason: Okay, I finally cracked this - it had nothing to do with this latest code, but I couldn't leave the mystery.  Well, it is still a little bit of a mystery.

It went away if I removed the other classes from test_filewriter.py.  The second clue was that the error and warnings appeared twice as often as expected.  Finally I noticed there were coming both from class WriteFileTests and from ScratchWriteDateTimeTests.  Then finally noticed that the latter is *derived* from the former.  Changed that to subclass from unittest.TestCase, and my issue went away, and the tests run normally with the `continue` line put back also.  So I haven't tried to figure out exactly why it causes trouble in both classes when the one is derived from the other, but it certainly is the source.  I suspect it is something to do with the temp file not being reset, and maybe the order of events depends on platform (I was testing on Windows, python 3.6.4).

So... @mrbean-bremen, if you don't mind updating that one line, then I'd be happy to merge this.
scaramallion: It looks like the change was made so that the `WriteFileTests` tests are run again but with `config.datetime_conversion = True`
darcymason: Yes, I think you are right, I remember that now that you bring it up.  But somehow that is not working out when the new test fails.  Well, it shouldn't fail, of course, so maybe it is a moot point, but it does seem the code is a bit fragile somehow.  Personally I like the 'test first' philosophy where you write the new unit test (so that it fails) before fixing the main code.
darcymason: ... I'll merge this and add a separate issue for the test code problem.
diff --git a/pydicom/filewriter.py b/pydicom/filewriter.py
index 01d9a4911..e283da86f 100644
--- a/pydicom/filewriter.py
+++ b/pydicom/filewriter.py
@@ -458,6 +458,9 @@ def write_dataset(fp, dataset, parent_encoding=default_encoding):
     tags = sorted(dataset.keys())
 
     for tag in tags:
+        # do not write retired Group Length (see PS3.5, 7.2)
+        if tag.element == 0 and tag.group > 6:
+            continue
         with tag_in_exception(tag):
             # write_data_element(fp, dataset.get_item(tag), dataset_encoding)
             # XXX for writing raw tags without converting to DataElement

Update filewriter group length fields
_From [darcymason@gmail.com](https://code.google.com/u/darcymason@gmail.com/) on December 10, 2008 22:48:30_

It looks like filewriter module does not recalc group length fields except
for file meta info section. Should make this the case for all groups.

_Original issue: http://code.google.com/p/pydicom/issues/detail?id=30_

diff --git a/pydicom/tests/test_filewriter.py b/pydicom/tests/test_filewriter.py
index f2bac9a81..362704140 100644
--- a/pydicom/tests/test_filewriter.py
+++ b/pydicom/tests/test_filewriter.py
@@ -39,6 +39,7 @@ ct_name = get_testdata_files("CT_small.dcm")[0]
 mr_name = get_testdata_files("MR_small.dcm")[0]
 jpeg_name = get_testdata_files("JPEG2000.dcm")[0]
 no_ts = get_testdata_files("meta_missing_tsyntax.dcm")[0]
+color_pl_name = get_testdata_files("color-pl.dcm")[0]
 datetime_name = mr_name
 
 unicode_name = get_charset_files("chrH31.dcm")[0]
@@ -194,6 +195,15 @@ class WriteFileTests(unittest.TestCase):
         ds = dcmread(fp, force=True)
         assert ds[0xFFFFFFFF].value == b'123456'
 
+    def test_write_removes_grouplength(self):
+        ds = dcmread(color_pl_name)
+        assert 0x00080000 in ds
+        ds.save_as(self.file_out, write_like_original=True)
+        self.file_out.seek(0)
+        ds = dcmread(self.file_out)
+        # group length has been removed
+        assert 0x00080000 not in ds
+
 
 class ScratchWriteDateTimeTests(WriteFileTests):
     """Write and reread simple or multi-value DA/DT/TM data elements"""

pip install -e .
parse_log_pytest
pytest
pytest
apt-get update apt-get install -y gcc
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@06e2352e8dc5e3ad0801ffa52339b469ae2b7b10#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_filewriter.py::WriteFileTests::test_write_removes_grouplength pydicom/tests/test_filewriter.py::ScratchWriteDateTimeTests::test_write_removes_grouplength
pydicom/tests/test_filewriter.py::WriteFileTests::testCT pydicom/tests/test_filewriter.py::WriteFileTests::testJPEG2000 pydicom/tests/test_filewriter.py::WriteFileTests::testListItemWriteBack pydicom/tests/test_filewriter.py::WriteFileTests::testMR pydicom/tests/test_filewriter.py::WriteFileTests::testMultiPN pydicom/tests/test_filewriter.py::WriteFileTests::testRTDose pydicom/tests/test_filewriter.py::WriteFileTests::testRTPlan pydicom/tests/test_filewriter.py::WriteFileTests::testUnicode pydicom/tests/test_filewriter.py::WriteFileTests::test_write_double_filemeta pydicom/tests/test_filewriter.py::WriteFileTests::test_write_ffff_ffff pydicom/tests/test_filewriter.py::WriteFileTests::test_write_no_ts pydicom/tests/test_filewriter.py::WriteFileTests::testwrite_short_uid pydicom/tests/test_filewriter.py::ScratchWriteDateTimeTests::testCT pydicom/tests/test_filewriter.py::ScratchWriteDateTimeTests::testJPEG2000 pydicom/tests/test_filewriter.py::ScratchWriteDateTimeTests::testListItemWriteBack pydicom/tests/test_filewriter.py::ScratchWriteDateTimeTests::testMR pydicom/tests/test_filewriter.py::ScratchWriteDateTimeTests::testMultiPN pydicom/tests/test_filewriter.py::ScratchWriteDateTimeTests::testRTDose pydicom/tests/test_filewriter.py::ScratchWriteDateTimeTests::testRTPlan pydicom/tests/test_filewriter.py::ScratchWriteDateTimeTests::testUnicode pydicom/tests/test_filewriter.py::ScratchWriteDateTimeTests::test_multivalue_DA pydicom/tests/test_filewriter.py::ScratchWriteDateTimeTests::test_write_double_filemeta pydicom/tests/test_filewriter.py::ScratchWriteDateTimeTests::test_write_ffff_ffff pydicom/tests/test_filewriter.py::ScratchWriteDateTimeTests::test_write_no_ts pydicom/tests/test_filewriter.py::ScratchWriteDateTimeTests::testwrite_short_uid pydicom/tests/test_filewriter.py::WriteDataElementTests::test_empty_AT pydicom/tests/test_filewriter.py::WriteDataElementTests::test_write_DA pydicom/tests/test_filewriter.py::WriteDataElementTests::test_write_DT pydicom/tests/test_filewriter.py::WriteDataElementTests::test_write_OD_explicit_little pydicom/tests/test_filewriter.py::WriteDataElementTests::test_write_OD_implicit_little pydicom/tests/test_filewriter.py::WriteDataElementTests::test_write_OL_explicit_little pydicom/tests/test_filewriter.py::WriteDataElementTests::test_write_OL_implicit_little pydicom/tests/test_filewriter.py::WriteDataElementTests::test_write_TM pydicom/tests/test_filewriter.py::WriteDataElementTests::test_write_UC_explicit_little pydicom/tests/test_filewriter.py::WriteDataElementTests::test_write_UC_implicit_little pydicom/tests/test_filewriter.py::WriteDataElementTests::test_write_UN_implicit_little pydicom/tests/test_filewriter.py::WriteDataElementTests::test_write_UR_explicit_little pydicom/tests/test_filewriter.py::WriteDataElementTests::test_write_UR_implicit_little pydicom/tests/test_filewriter.py::WriteDataElementTests::test_write_empty_LO pydicom/tests/test_filewriter.py::WriteDataElementTests::test_write_multi_DA pydicom/tests/test_filewriter.py::WriteDataElementTests::test_write_multi_DT pydicom/tests/test_filewriter.py::WriteDataElementTests::test_write_multi_TM pydicom/tests/test_filewriter.py::WriteDataElementTests::test_write_unknown_vr_raises pydicom/tests/test_filewriter.py::TestCorrectAmbiguousVR::test_lut_descriptor pydicom/tests/test_filewriter.py::TestCorrectAmbiguousVR::test_overlay pydicom/tests/test_filewriter.py::TestCorrectAmbiguousVR::test_pixel_data pydicom/tests/test_filewriter.py::TestCorrectAmbiguousVR::test_pixel_representation_vm_one pydicom/tests/test_filewriter.py::TestCorrectAmbiguousVR::test_pixel_representation_vm_three pydicom/tests/test_filewriter.py::TestCorrectAmbiguousVR::test_sequence pydicom/tests/test_filewriter.py::TestCorrectAmbiguousVR::test_waveform_bits_allocated pydicom/tests/test_filewriter.py::TestCorrectAmbiguousVRElement::test_not_ambiguous pydicom/tests/test_filewriter.py::TestCorrectAmbiguousVRElement::test_pixel_data_not_ow_or_ob pydicom/tests/test_filewriter.py::WriteAmbiguousVRTests::test_write_explicit_vr_big_endian pydicom/tests/test_filewriter.py::WriteAmbiguousVRTests::test_write_explicit_vr_little_endian pydicom/tests/test_filewriter.py::WriteAmbiguousVRTests::test_write_explicit_vr_raises pydicom/tests/test_filewriter.py::ScratchWriteTests::testImpl_LE_deflen_write pydicom/tests/test_filewriter.py::TestWriteToStandard::test_preamble_default pydicom/tests/test_filewriter.py::TestWriteToStandard::test_preamble_custom pydicom/tests/test_filewriter.py::TestWriteToStandard::test_no_preamble pydicom/tests/test_filewriter.py::TestWriteToStandard::test_none_preamble pydicom/tests/test_filewriter.py::TestWriteToStandard::test_bad_preamble pydicom/tests/test_filewriter.py::TestWriteToStandard::test_prefix pydicom/tests/test_filewriter.py::TestWriteToStandard::test_prefix_none pydicom/tests/test_filewriter.py::TestWriteToStandard::test_ds_changed pydicom/tests/test_filewriter.py::TestWriteToStandard::test_transfer_syntax_added pydicom/tests/test_filewriter.py::TestWriteToStandard::test_transfer_syntax_not_added pydicom/tests/test_filewriter.py::TestWriteToStandard::test_transfer_syntax_raises pydicom/tests/test_filewriter.py::TestWriteToStandard::test_media_storage_sop_class_uid_added pydicom/tests/test_filewriter.py::TestWriteToStandard::test_write_no_file_meta pydicom/tests/test_filewriter.py::TestWriteToStandard::test_raise_no_file_meta pydicom/tests/test_filewriter.py::TestWriteToStandard::test_add_file_meta pydicom/tests/test_filewriter.py::TestWriteToStandard::test_standard pydicom/tests/test_filewriter.py::TestWriteToStandard::test_commandset_no_written pydicom/tests/test_filewriter.py::TestWriteFileMetaInfoToStandard::test_bad_elements pydicom/tests/test_filewriter.py::TestWriteFileMetaInfoToStandard::test_missing_elements pydicom/tests/test_filewriter.py::TestWriteFileMetaInfoToStandard::test_group_length pydicom/tests/test_filewriter.py::TestWriteFileMetaInfoToStandard::test_group_length_updated pydicom/tests/test_filewriter.py::TestWriteFileMetaInfoToStandard::test_version pydicom/tests/test_filewriter.py::TestWriteFileMetaInfoToStandard::test_implementation_version_name_length pydicom/tests/test_filewriter.py::TestWriteFileMetaInfoToStandard::test_implementation_class_uid_length pydicom/tests/test_filewriter.py::TestWriteFileMetaInfoToStandard::test_filelike_position pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_commandset pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_commandset_dataset pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_commandset_filemeta pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_commandset_filemeta_dataset pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_dataset pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_ds_unchanged pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_file_meta_unchanged pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_filemeta_dataset pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_no_preamble pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_preamble_commandset pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_preamble_commandset_dataset pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_preamble_commandset_filemeta pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_preamble_commandset_filemeta_dataset pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_preamble_custom pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_preamble_dataset pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_preamble_default pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_preamble_filemeta_dataset pydicom/tests/test_filewriter.py::TestWriteNonStandard::test_read_write_identical pydicom/tests/test_filewriter.py::TestWriteFileMetaInfoNonStandard::test_bad_elements pydicom/tests/test_filewriter.py::TestWriteFileMetaInfoNonStandard::test_filelike_position pydicom/tests/test_filewriter.py::TestWriteFileMetaInfoNonStandard::test_group_length_updated pydicom/tests/test_filewriter.py::TestWriteFileMetaInfoNonStandard::test_meta_unchanged pydicom/tests/test_filewriter.py::TestWriteFileMetaInfoNonStandard::test_missing_elements pydicom/tests/test_filewriter.py::TestWriteFileMetaInfoNonStandard::test_transfer_syntax_not_added pydicom/tests/test_filewriter.py::TestWriteNumbers::test_write_empty_value pydicom/tests/test_filewriter.py::TestWriteNumbers::test_write_list pydicom/tests/test_filewriter.py::TestWriteNumbers::test_write_singleton pydicom/tests/test_filewriter.py::TestWriteNumbers::test_exception pydicom/tests/test_filewriter.py::TestWriteNumbers::test_write_big_endian pydicom/tests/test_filewriter.py::TestWritePN::test_no_encoding_unicode pydicom/tests/test_filewriter.py::TestWritePN::test_no_encoding pydicom/tests/test_filewriter.py::TestWriteDT::test_format_dt pydicom/tests/test_filewriter.py::TestWriteUndefinedLengthPixelData::test_big_endian_correct_data pydicom/tests/test_filewriter.py::TestWriteUndefinedLengthPixelData::test_big_endian_incorrect_data pydicom/tests/test_filewriter.py::TestWriteUndefinedLengthPixelData::test_little_endian_correct_data pydicom/tests/test_filewriter.py::TestWriteUndefinedLengthPixelData::test_little_endian_incorrect_data
pydicom/filewriter.py
pydicom/filewriter.py