Repository: pydicom/pydicom

Issue:
Dataset.private_block inconsistent behavior with create=True
Using Dataset.private_block to get a private block for an available private creator with the flag create=True yields inconsistent behavior. Sometimes it recognizes the available private creator and sometimes it does not and adds a new tag for it.  

I [expect](https://pydicom.github.io/pydicom/dev/reference/generated/pydicom.dataset.Dataset.html#pydicom.dataset.Dataset.private_block) Dataset.private_block(group_number, private_creator, create=True) would recognize an available private_creator if present in a dicom file and would not add a new tag for it. 

Reproduction code:

```
from pydicom import dcmread
from pydicom.data import get_testdata_files

ct_filename = get_testdata_files("CT_small")[0]
ds = dcmread(ct_filename)
block = ds.private_block(0x11, 'GEMS_PATI_01', create=True)

ds.private_creators(0x11)
ds.private_creators(0x11)[0] == ds.private_creators(0x11)[1]
```

Output is:
```
['GEMS_PATI_01', 'GEMS_PATI_01']
True
```

Working with other files, I've seen this behavior is not consistent. Sometimes I would get the expected results. I have not tested it enough for the specific file above.

My environment (Running with docker from PyCharm):
Linux-4.15.0-74-generic-x86_64-with-debian-buster-sid
Python  3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 19:07:31)
[GCC 7.3.0]
pydicom  1.4.2

Discussion:
scaramallion: Yeah, I can restart Travis but not appveyor
darcymason: Apparently closing and re-opening a pull request will re-trigger builds... I'll see if I can re-open after the close...

Patch:
diff --git a/doc/release_notes/v2.0.0.rst b/doc/release_notes/v2.0.0.rst
index 17443d11e..4c137b142 100644
--- a/doc/release_notes/v2.0.0.rst
+++ b/doc/release_notes/v2.0.0.rst
@@ -30,3 +30,4 @@ Fixes
 * Fixed :func:`~pydicom.pixel_data_handlers.util.apply_voi_lut` and
   :func:`~pydicom.pixel_data_handlers.util.apply_modality_lut` not handling
   (0028,3006) *LUT Data* with a VR of **OW** (:issue:`1073`)
+* Fixed access to private creator tag in raw datasets (:issue:`1078`)
diff --git a/pydicom/dataset.py b/pydicom/dataset.py
index c69c15b4d..de741cb89 100644
--- a/pydicom/dataset.py
+++ b/pydicom/dataset.py
@@ -929,7 +929,7 @@ class Dataset(dict):
                     return new_block()
                 else:
                     break
-            if self._dict[private_creator_tag].value == private_creator:
+            if self[private_creator_tag].value == private_creator:
                 return new_block()
 
         raise KeyError(
@@ -972,7 +972,7 @@ class Dataset(dict):
             private_creator_tag = Tag(group, element)
             if private_creator_tag not in self._dict:
                 break
-            private_creators.append(self._dict[private_creator_tag].value)
+            private_creators.append(self[private_creator_tag].value)
         return private_creators
 
     def get_private_item(self, group, element_offset, private_creator):


Test patch:
diff --git a/pydicom/tests/test_dataset.py b/pydicom/tests/test_dataset.py
index f28171e85..daad7f952 100644
--- a/pydicom/tests/test_dataset.py
+++ b/pydicom/tests/test_dataset.py
@@ -955,6 +955,17 @@ class TestDataset(object):
         item = ds.get_private_item(0x0009, 0x02, 'Creator 2.0')
         assert 2 == item.value
 
+    def test_private_creator_from_raw_ds(self):
+        # regression test for #1078
+        ct_filename = get_testdata_files("CT_small")[0]
+        ds = dcmread(ct_filename)
+        ds.private_block(0x11, 'GEMS_PATI_01', create=True)
+        assert ['GEMS_PATI_01'] == ds.private_creators(0x11)
+
+        assert [] == ds.private_creators(0x13)
+        ds.private_block(0x13, 'GEMS_PATI_01', create=True)
+        assert ['GEMS_PATI_01'] == ds.private_creators(0x13)
+
     def test_add_new_private_tag(self):
         ds = Dataset()
         ds.add_new(0x00080005, 'CS', 'ISO_IR 100')