Repository: pandas-dev/pandas

Issue:
"df.get(None)" throws error in 0.13 -> regression?
This works with pandas 0.12:

``` python
from ggplot import meat
meat.get(None)
[returns None]
```

But throws an error in 0.13 (RC):

``` python
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-11-86be6a7317b8> in <module>()
----> 1 meat.get(None)

C:\portabel\Python27\lib\site-packages\pandas\core\generic.pyc in get(self, key, default)
    961         """
    962         try:
--> 963             return self[key]
    964         except KeyError:
    965             return default

C:\portabel\Python27\lib\site-packages\pandas\core\frame.pyc in __getitem__(self, key)
   1626             return self._getitem_multilevel(key)
   1627         else:
-> 1628             return self._getitem_column(key)
   1629 
   1630     def _getitem_column(self, key):

C:\portabel\Python27\lib\site-packages\pandas\core\frame.pyc in _getitem_column(self, key)
   1633         # get column
   1634         if self.columns.is_unique:
-> 1635             return self._get_item_cache(key)
   1636 
   1637         # duplicate columns & possible reduce dimensionaility

C:\portabel\Python27\lib\site-packages\pandas\core\generic.pyc in _get_item_cache(self, item)
    972         res = cache.get(item)
    973         if res is None:
--> 974             values = self._data.get(item)
    975             res = self._box_item_values(item, values)
    976             cache[item] = res

C:\portabel\Python27\lib\site-packages\pandas\core\internals.pyc in get(self, item)
   2737             if isnull(item):
   2738                 indexer = np.arange(len(self.items))[isnull(self.items)]
-> 2739                 return self.get_for_nan_indexer(indexer)
   2740 
   2741             _, block = self._find_block(item)

C:\portabel\Python27\lib\site-packages\pandas\core\internals.pyc in get_for_nan_indexer(self, indexer)
   2789                 indexer = indexer.item()
   2790             else:
-> 2791                 raise ValueError("cannot label index with a null key")
   2792 
   2793         # take a nan indexer and return the values

ValueError: cannot label index with a null key
```

Not sure if that is intentional as this broke some code in the facet_wrap in ggplot (which now will get some update against this :-) )



Discussion:
that seems like a very odd thing to do as its trying to get something indexed by `None`

@jreback , close as wontfix? this looks like reasonable behavior to me

what is `meat`? a sub-class of frame?

?

```
In [62]: DataFrame().get(None)
ValueError: cannot label index with a null key
```

easy to fix I think


Resolving patch:
diff --git a/pandas/core/generic.py b/pandas/core/generic.py
--- a/pandas/core/generic.py
+++ b/pandas/core/generic.py
@@ -981,7 +981,7 @@ def get(self, key, default=None):
         """
         try:
             return self[key]
-        except KeyError:
+        except (KeyError, ValueError):
             return default
 
     def __getitem__(self, item):


Test patch:
diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py
--- a/pandas/tests/test_frame.py
+++ b/pandas/tests/test_frame.py
@@ -147,6 +147,11 @@ def test_get(self):
         self.assert_(self.frame.get('foo') is None)
         assert_series_equal(self.frame.get('foo', self.frame['B']),
                             self.frame['B'])
+        # None
+        # GH 5652
+        for df in [DataFrame(), DataFrame(columns=list('AB')), DataFrame(columns=list('AB'),index=range(3)) ]:
+            result = df.get(None)
+            self.assert_(result is None)
 
     def test_getitem_iterator(self):
         idx = iter(['A', 'B', 'C'])
diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py
--- a/pandas/tests/test_series.py
+++ b/pandas/tests/test_series.py
@@ -724,6 +724,12 @@ def test_getitem_get(self):
         d = self.ts.index[0] - datetools.bday
         self.assertRaises(KeyError, self.ts.__getitem__, d)
 
+        # None
+        # GH 5652
+        for s in [Series(), Series(index=list('abc'))]:
+            result = s.get(None)
+            self.assert_(result is None)
+
     def test_iget(self):
         s = Series(np.random.randn(10), index=lrange(0, 20, 2))
         for i in range(len(s)):