Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

(1) add a get() method like dicts have, (2) throw KeyError, not Exception, when a column isn't found #521

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+8 −1
Split
View
@@ -1062,7 +1062,7 @@ def _getitem_array(self, key):
indexer = self.columns.get_indexer(key)
mask = indexer == -1
if mask.any():
- raise Exception("No column(s) named: %s" % str(key[mask]))
+ raise KeyError("No column(s) named: %s" % str(key[mask]))
return self.reindex(columns=key)
def _slice(self, slobj, axis=0):
@@ -1203,6 +1203,13 @@ def pop(self, item):
"""
return NDFrame.pop(self, item)
+ def get(self, column, default=None):
+ try:
@wesm

wesm Dec 21, 2011

Owner

docstring, pretty please? in the style of the rest of the library preferably :)

+ return self[column]
+ except KeyError:
+ return default
+
+
# to support old APIs
@property
def _series(self):