pep8speaks: Hello @mrbean-bremen! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:

* In the file [`pydicom/dataset.py`](https://github.com/pydicom/pydicom/blob/3f59de3d5521a392c883fbe4a82af3a794ed3b84/pydicom/dataset.py):

> [Line 1160:73](https://github.com/pydicom/pydicom/blob/3f59de3d5521a392c883fbe4a82af3a794ed3b84/pydicom/dataset.py#L1160): [W291](https://duckduckgo.com/?q=pep8%20W291) trailing whitespace




mrbean-bremen: Ok, done. Not the best idea to do the editing on the smartphone, even for a small change... 
diff --git a/doc/whatsnew/v1.3.0.rst b/doc/whatsnew/v1.3.0.rst
index 011e8d757..4f642ed99 100644
--- a/doc/whatsnew/v1.3.0.rst
+++ b/doc/whatsnew/v1.3.0.rst
@@ -29,6 +29,8 @@ Enhancements
 
 Fixes
 .....
+* Correctly handle `Dataset.pop` and `Dataset.setdefault` for tuple and
+  keyword arguments (:issue:`852`)
 * Correctly handle encoding errors when any of the encodings are invalid
   (not just the first) (:issue:`850`)
 * Do not raise while resolving an ambiguous VR dependent on
diff --git a/pydicom/dataset.py b/pydicom/dataset.py
index b91ab5cc3..c30ada8db 100644
--- a/pydicom/dataset.py
+++ b/pydicom/dataset.py
@@ -25,7 +25,7 @@ from itertools import takewhile
 import pydicom  # for dcmwrite
 import pydicom.charset
 import pydicom.config
-from pydicom import compat
+from pydicom import compat, datadict
 from pydicom._version import __version_info__
 from pydicom.charset import default_encoding, convert_encodings
 from pydicom.config import logger
@@ -447,18 +447,14 @@ class Dataset(dict):
         bool
             True if the DataElement is in the Dataset, False otherwise.
         """
-        if isinstance(name, (str, compat.text_type)):
-            tag = tag_for_keyword(name)
-        else:
-            try:
-                tag = Tag(name)
-            except Exception:
-                return False
+        try:
+            tag = Tag(name)
+        except (ValueError, OverflowError):
+            return False
         # Test against None as (0000,0000) is a possible tag
         if tag is not None:
             return tag in self._dict
-        else:
-            return name in self._dict  # will no doubt raise an exception
+        return name in self._dict  # will no doubt raise an exception
 
     def decode(self):
         """Apply character set decoding to all DataElements in the Dataset.
@@ -1089,14 +1085,98 @@ class Dataset(dict):
         """Delete all data elements."""
         self._dict.clear()
 
-    def pop(self, *args, **kwargs):
-        return self._dict.pop(*args, **kwargs)
+    def pop(self, key, *args):
+        """Emulate dictionary `pop`, but additionally support tag ID tuple
+        and DICOM keyword.
+
+        Removes the data element for `key` if it exists and returns it,
+        otherwise returns a default value if given or raises `KeyError`.
+
+        Parameters
+        ----------
+        key: int or str or 2-tuple
+            if tuple - the group and element number of the DICOM tag
+            if int - the combined group/element number
+            if str - the DICOM keyword of the tag
+
+        *args: zero or one argument
+            defines the behavior if no tag exists for `key`: if given,
+            it defines the return value, if not given, `KeyError` is raised
+
+        Returns
+        -------
+        The data element for `key` if it exists, or the default value if given.
+
+        Raises
+        ------
+        KeyError
+            If the key is not a valid tag ID or keyword.
+            If the tag does not exist and no default is given.
+        """
+        try:
+            tag = Tag(key)
+        except (ValueError, OverflowError):
+            return self._dict.pop(key, *args)
+        return self._dict.pop(tag, *args)
 
     def popitem(self):
         return self._dict.popitem()
 
-    def setdefault(self,  *args, **kwargs):
-        return self._dict.setdefault(*args, **kwargs)
+    def setdefault(self, key, default=None):
+        """Emulate dictionary `setdefault`, but additionally support
+        tag ID tuple and DICOM keyword for `key`, and data element value
+        for `default`.
+
+        .. usage:
+
+        >>> ds = Dataset()
+        >>> pname = ds.setdefault((0x0010, 0x0010), "Test")
+        >>> pname
+        (0010, 0010) Patient's Name                      PN: 'Test'
+        >>> pname.value
+        'Test'
+        >>> psex = ds.setdefault('PatientSex',
+        ...     DataElement(0x00100040, 'CS', 'F'))
+        >>> psex.value
+        'F'
+
+        Parameters
+        ----------
+        key: int or str or 2-tuple
+            if tuple - the group and element number of the DICOM tag
+            if int - the combined group/element number
+            if str - the DICOM keyword of the tag
+
+        default: DataElement or value type or None
+            The default value that is inserted and returned if no data
+            element exists for the given key.
+            If it is not of type DataElement, a DataElement is constructed
+            instead for the given tag ID and default as value. This is only
+            possible for known tags (e.g. tags found via the dictionary
+            lookup).
+
+        Returns
+        -------
+        The data element for `key` if it exists, or the default value if
+        it is a DataElement or None, or a DataElement constructed with
+        `default` as value.
+
+        Raises
+        ------
+        KeyError
+            If the key is not a valid tag ID or keyword.
+            If no tag exists for `key`, default is not a DataElement
+            and not None, and key is not a known DICOM tag.
+        """
+        if key in self:
+            return self[key]
+        if default is not None:
+            if not isinstance(default, DataElement):
+                tag = Tag(key)
+                vr = datadict.dictionary_VR(tag)
+                default = DataElement(Tag(key), vr, default)
+            self[key] = default
+        return default
 
     def convert_pixel_data(self):
         """Convert the Pixel Data to a numpy array internally.

pop from dataset raises exception
#### Description
KeyError exception thrown while popping existing key from a dataset

#### Code to Reproduce
```python3
import pydicom
filepath = "filedir/filename.dcm" # path to the DICOM file
dataset = pydicom.dcmread(filepath)
key = (0x0020, 0x0013) # Instance Number
assert key in dataset # ok
dataset.pop(key) # throws KeyError
```

#### Expected Results
Normally, the code should not fail.

#### Actual Results
A KeyError is thrown while calling `dataset.pop`:
```
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/pydicom/dataset.py", line 783, in pop
    return self._dict.pop(*args, **kwargs)
KeyError: (32, 19)
```

#### Versions
Linux-4.9.0-9-amd64-x86_64-with-debian-9.9
Python 3.5.3 (default, Sep 27 2018, 17:25:39) 
[GCC 6.3.0 20170516]
pydicom 1.2.2
diff --git a/pydicom/tests/test_dataset.py b/pydicom/tests/test_dataset.py
index c5bc064ca..932551bbf 100644
--- a/pydicom/tests/test_dataset.py
+++ b/pydicom/tests/test_dataset.py
@@ -235,12 +235,30 @@ class DatasetTests(unittest.TestCase):
 
     def test_pop(self):
         ds = self.dummy_dataset()
+        with pytest.raises(KeyError):
+            ds.pop(0x300a00b244)
         assert 'default' == ds.pop('dummy', 'default')
         elem = ds.pop(0x300a00b2)
         assert 'unit001' == elem.value
         with pytest.raises(KeyError):
             ds.pop(0x300a00b2)
 
+    def test_pop_using_tuple(self):
+        ds = self.dummy_dataset()
+        elem = ds.pop((0x300a, 0x00b2))
+        assert 'unit001' == elem.value
+        with pytest.raises(KeyError):
+            ds.pop((0x300a, 0x00b2))
+
+    def test_pop_using_keyword(self):
+        ds = self.dummy_dataset()
+        with pytest.raises(KeyError):
+            ds.pop('InvalidName')
+        elem = ds.pop('TreatmentMachineName')
+        assert 'unit001' == elem.value
+        with pytest.raises(KeyError):
+            ds.pop('TreatmentMachineName')
+
     def test_popitem(self):
         ds = self.dummy_dataset()
         elem = ds.popitem()
@@ -257,6 +275,33 @@ class DatasetTests(unittest.TestCase):
         assert elem.value == 'Test'
         assert 2 == len(ds)
 
+    def test_setdefault_tuple(self):
+        ds = self.dummy_dataset()
+        elem = ds.setdefault((0x300a, 0x00b2), 'foo')
+        assert 'unit001' == elem.value
+        elem = ds.setdefault((0x0010, 0x0010), DataElement(
+            0x00100010, 'PN', "Test"))
+        assert elem.value == 'Test'
+        assert 2 == len(ds)
+
+    def test_setdefault_use_value(self):
+        ds = self.dummy_dataset()
+        elem = ds.setdefault((0x0010, 0x0010), "Test")
+        assert elem.value == 'Test'
+        assert 2 == len(ds)
+        with pytest.raises(KeyError, match=r'Tag \(0011, 0010\) not found '
+                                           r'in DICOM dictionary'):
+            ds.setdefault((0x0011, 0x0010), "Test")
+
+    def test_setdefault_keyword(self):
+        ds = self.dummy_dataset()
+        elem = ds.setdefault('TreatmentMachineName', 'foo')
+        assert 'unit001' == elem.value
+        elem = ds.setdefault('PatientName',
+                             DataElement(0x00100010, 'PN', "Test"))
+        assert elem.value == 'Test'
+        assert 2 == len(ds)
+
     def testGetExists1(self):
         """Dataset: dataset.get() returns an existing item by name.........."""
         ds = self.dummy_dataset()

pip install -e .
parse_log_pytest
requirements.txt
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==22.2.0
certifi==2021.5.30
importlib-metadata==4.8.3
iniconfig==1.1.1
packaging==21.3
pluggy==1.0.0
py==1.11.0
-e git+https://github.com/pydicom/pydicom.git@de7ac39a05dd35c1370b6ba341a6a123fdb7e3fb#egg=pydicom
pyparsing==3.1.4
pytest==7.0.1
tomli==1.2.3
typing_extensions==4.1.1
zipp==3.6.0

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
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_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
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - 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
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - packaging==21.3
      - pluggy==1.0.0
      - py==1.11.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - zipp==3.6.0
prefix: /opt/conda/envs/pydicom

pydicom/tests/test_dataset.py::DatasetTests::test_pop_using_keyword pydicom/tests/test_dataset.py::DatasetTests::test_pop_using_tuple pydicom/tests/test_dataset.py::DatasetTests::test_setdefault_keyword pydicom/tests/test_dataset.py::DatasetTests::test_setdefault_tuple pydicom/tests/test_dataset.py::DatasetTests::test_setdefault_use_value
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::testEqualityNoSequence pydicom/tests/test_dataset.py::DatasetTests::testEqualityNotDataset pydicom/tests/test_dataset.py::DatasetTests::testEqualityPrivate pydicom/tests/test_dataset.py::DatasetTests::testEqualitySequence 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_new_private_tag 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_clear pydicom/tests/test_dataset.py::DatasetTests::test_contains pydicom/tests/test_dataset.py::DatasetTests::test_data_element pydicom/tests/test_dataset.py::DatasetTests::test_delete_private_tag 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_dir_subclass pydicom/tests/test_dataset.py::DatasetTests::test_empty_slice pydicom/tests/test_dataset.py::DatasetTests::test_equality_elements pydicom/tests/test_dataset.py::DatasetTests::test_exit_exception pydicom/tests/test_dataset.py::DatasetTests::test_for_stray_raw_data_element pydicom/tests/test_dataset.py::DatasetTests::test_formatted_lines pydicom/tests/test_dataset.py::DatasetTests::test_formatted_lines_known_uid pydicom/tests/test_dataset.py::DatasetTests::test_get_item pydicom/tests/test_dataset.py::DatasetTests::test_get_item_slice pydicom/tests/test_dataset.py::DatasetTests::test_get_private_item 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_ffff 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_original_encoding pydicom/tests/test_dataset.py::DatasetTests::test_iterall pydicom/tests/test_dataset.py::DatasetTests::test_matching_tags pydicom/tests/test_dataset.py::DatasetTests::test_pixel_array_already_have pydicom/tests/test_dataset.py::DatasetTests::test_pixel_array_id_changed pydicom/tests/test_dataset.py::DatasetTests::test_pixel_array_unknown_syntax pydicom/tests/test_dataset.py::DatasetTests::test_pop pydicom/tests/test_dataset.py::DatasetTests::test_popitem pydicom/tests/test_dataset.py::DatasetTests::test_private_block pydicom/tests/test_dataset.py::DatasetTests::test_private_creators 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_save_as pydicom/tests/test_dataset.py::DatasetTests::test_set_convert_private_elem_from_raw pydicom/tests/test_dataset.py::DatasetTests::test_setdefault 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_update_with_dataset 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::DatasetElementsTests::test_ensure_file_meta pydicom/tests/test_dataset.py::DatasetElementsTests::test_fix_meta_info pydicom/tests/test_dataset.py::DatasetElementsTests::test_validate_and_correct_file_meta pydicom/tests/test_dataset.py::FileDatasetTests::test_creation_with_container pydicom/tests/test_dataset.py::FileDatasetTests::test_dataset_overrides_all_dict_attributes pydicom/tests/test_dataset.py::FileDatasetTests::test_equality_file_meta
pydicom/dataset.py doc/whatsnew/v1.3.0.rst
pydicom/dataset.py doc/whatsnew/v1.3.0.rst