-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
NotImplementedError messages doc update #7872 #7899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,11 @@ class SettingWithCopyWarning(Warning): | |
class AmbiguousIndexError(PandasError, KeyError): | ||
pass | ||
|
||
class AbstractMethodError(NotImplementedError): | ||
def __init__(self,m): | ||
self.message = m | ||
def __str__(self): | ||
return "This method must be defined on the concrete class - "+self.message | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Be nice to include the problematic class name in error message. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use inspect to do this (would need some testing esp. 2.6 & 3.x):
(perhaps there's a neater way?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking back, I'd hoped/wanted this to print A... dang. |
||
|
||
_POSSIBLY_CAST_DTYPES = set([np.dtype(t).name | ||
for t in ['O', 'int8', | ||
|
@@ -134,7 +139,7 @@ def _isnull_new(obj): | |
return lib.checknull(obj) | ||
# hack (for now) because MI registers as ndarray | ||
elif isinstance(obj, pd.MultiIndex): | ||
raise NotImplementedError("isnull is not defined for MultiIndex") | ||
raise AbstractMethodError("isnull is not defined for MultiIndex") | ||
elif isinstance(obj, (ABCSeries, np.ndarray)): | ||
return _isnull_ndarraylike(obj) | ||
elif isinstance(obj, ABCGeneric): | ||
|
@@ -160,7 +165,7 @@ def _isnull_old(obj): | |
return lib.checknull_old(obj) | ||
# hack (for now) because MI registers as ndarray | ||
elif isinstance(obj, pd.MultiIndex): | ||
raise NotImplementedError("isnull is not defined for MultiIndex") | ||
raise AbstractMethodError("isnull is not defined for MultiIndex") | ||
elif isinstance(obj, (ABCSeries, np.ndarray)): | ||
return _isnull_ndarraylike_old(obj) | ||
elif isinstance(obj, ABCGeneric): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,7 +135,7 @@ def _init_mgr(self, mgr, axes=None, dtype=None, copy=False): | |
|
||
@property | ||
def _constructor(self): | ||
raise NotImplementedError | ||
raise NotImplementedError("NDFrame _constructor") | ||
|
||
def __unicode__(self): | ||
# unicode representation based upon iterating over self | ||
|
@@ -150,7 +150,7 @@ def _local_dir(self): | |
|
||
@property | ||
def _constructor_sliced(self): | ||
raise NotImplementedError | ||
raise NotImplementedError("NDFrame _constructor_sliced") | ||
|
||
#---------------------------------------------------------------------- | ||
# Axis | ||
|
@@ -1073,7 +1073,7 @@ def _iget_item_cache(self, item): | |
return lower | ||
|
||
def _box_item_values(self, key, values): | ||
raise NotImplementedError | ||
raise NotImplementedError("NDFrame _box_item_values") | ||
|
||
def _maybe_cache_changed(self, item, value): | ||
""" | ||
|
@@ -1653,7 +1653,7 @@ def _needs_reindex_multi(self, axes, method, level): | |
method is None and level is None and not self._is_mixed_type) | ||
|
||
def _reindex_multi(self, axes, copy, fill_value): | ||
return NotImplemented | ||
raise NotImplementedError("NDFrame _reindex_multi") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. first 4 are abstract |
||
|
||
_shared_docs['reindex_axis'] = ( | ||
"""Conform input object to new index with optional filling logic, | ||
|
@@ -2179,7 +2179,7 @@ def fillna(self, value=None, method=None, axis=0, inplace=False, | |
raise ValueError('must specify a fill method or value') | ||
if self._is_mixed_type and axis == 1: | ||
if inplace: | ||
raise NotImplementedError() | ||
raise NotImplementedError("fillna with inplace=True and _is_mixed_type=True and axis=1") | ||
result = self.T.fillna(method=method, limit=limit).T | ||
|
||
# need to downcast here because of all of the transposes | ||
|
@@ -2880,7 +2880,7 @@ def first(self, offset): | |
""" | ||
from pandas.tseries.frequencies import to_offset | ||
if not isinstance(self.index, DatetimeIndex): | ||
raise NotImplementedError | ||
raise NotImplementedError("Currently implemented for DatatimeIndex instance only") | ||
|
||
if len(self.index) == 0: | ||
return self | ||
|
@@ -2914,7 +2914,7 @@ def last(self, offset): | |
""" | ||
from pandas.tseries.frequencies import to_offset | ||
if not isinstance(self.index, DatetimeIndex): | ||
raise NotImplementedError | ||
raise NotImplementedError("Currently implemented for DatatimeIndex instance only") | ||
|
||
if len(self.index) == 0: | ||
return self | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,7 +283,7 @@ def _set_grouper(self, obj, sort=False): | |
return self.grouper | ||
|
||
def _get_binner_for_grouping(self, obj): | ||
raise NotImplementedError | ||
raise NotImplementedError("Binner for grouping") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these are all abstract |
||
|
||
@property | ||
def groups(self): | ||
|
@@ -644,7 +644,7 @@ def _python_apply_general(self, f): | |
not_indexed_same=mutated) | ||
|
||
def aggregate(self, func, *args, **kwargs): | ||
raise NotImplementedError | ||
raise NotImplementedError("Groupby aggregrate") | ||
|
||
@Appender(_agg_doc) | ||
def agg(self, func, *args, **kwargs): | ||
|
@@ -654,7 +654,7 @@ def _iterate_slices(self): | |
yield self.name, self._selected_obj | ||
|
||
def transform(self, func, *args, **kwargs): | ||
raise NotImplementedError | ||
raise NotImplementedError("Groupby transform") | ||
|
||
def mean(self): | ||
""" | ||
|
@@ -1041,7 +1041,7 @@ def _python_agg_general(self, func, *args, **kwargs): | |
return self._wrap_aggregated_output(output) | ||
|
||
def _wrap_applied_output(self, *args, **kwargs): | ||
raise NotImplementedError | ||
raise NotImplementedError("Groupby wrap applied output") | ||
|
||
def _concat_objects(self, keys, values, not_indexed_same=False): | ||
from pandas.tools.merge import concat | ||
|
@@ -1404,7 +1404,7 @@ def aggregate(self, values, how, axis=0): | |
swapped = True | ||
values = values.swapaxes(0, axis) | ||
if arity > 1: | ||
raise NotImplementedError | ||
raise NotImplementedError("BaseGrouper aggregate for arity > 1") | ||
out_shape = (self.ngroups,) + values.shape[1:] | ||
|
||
if is_numeric_dtype(values.dtype): | ||
|
@@ -1459,7 +1459,7 @@ def _aggregate(self, result, counts, values, how, is_numeric): | |
comp_ids, _, ngroups = self.group_info | ||
if values.ndim > 3: | ||
# punting for now | ||
raise NotImplementedError | ||
raise NotImplementedError("BaseGrouper aggregrate for > 3 dimensions") | ||
elif values.ndim > 2: | ||
for i, chunk in enumerate(values.transpose(2, 0, 1)): | ||
|
||
|
@@ -1695,7 +1695,7 @@ def _aggregate(self, result, counts, values, how, is_numeric=True): | |
|
||
if values.ndim > 3: | ||
# punting for now | ||
raise NotImplementedError | ||
raise NotImplementedError("BinGrouper aggregate for > 3 dimensions") | ||
elif values.ndim > 2: | ||
for i, chunk in enumerate(values.transpose(2, 0, 1)): | ||
agg_func(result[:, :, i], counts, chunk, self.bins) | ||
|
@@ -2399,7 +2399,7 @@ def aggregate(self, arg, *args, **kwargs): | |
if self._selection is not None: | ||
subset = obj | ||
if isinstance(subset, DataFrame): | ||
raise NotImplementedError | ||
raise NotImplementedError("aggregate not implemented for subset being a Dataframe") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this and next one are ok as NotImplementedError |
||
|
||
for fname, agg_how in compat.iteritems(arg): | ||
colg = SeriesGroupBy(subset, selection=self._selection, | ||
|
@@ -2459,7 +2459,7 @@ def _aggregate_multiple_funcs(self, arg): | |
from pandas.tools.merge import concat | ||
|
||
if self.axis != 0: | ||
raise NotImplementedError | ||
raise NotImplementedError("Currently implemented for axis = 0") | ||
|
||
obj = self._obj_with_exclusions | ||
|
||
|
@@ -2509,7 +2509,7 @@ def _aggregate_generic(self, func, *args, **kwargs): | |
return self._wrap_generic_output(result, obj) | ||
|
||
def _wrap_aggregated_output(self, output, names=None): | ||
raise NotImplementedError | ||
raise NotImplementedError("NDFrameGroupBy wrap aggregated output") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. abstract |
||
|
||
def _aggregate_item_by_item(self, func, *args, **kwargs): | ||
# only for axis==0 | ||
|
@@ -3050,7 +3050,7 @@ def _iterate_slices(self): | |
slice_axis = self._selection_list | ||
slicer = lambda x: self._selected_obj[x] | ||
else: | ||
raise NotImplementedError | ||
raise NotImplementedError("Currently implemented for axis = 0") | ||
|
||
for val in slice_axis: | ||
if val in self.exclusions: | ||
|
@@ -3115,10 +3115,10 @@ def _aggregate_item_by_item(self, func, *args, **kwargs): | |
new_axes[self.axis] = self.grouper.result_index | ||
return Panel._from_axes(result, new_axes) | ||
else: | ||
raise NotImplementedError | ||
raise NotImplementedError("Currently implemented for axis>0") | ||
|
||
def _wrap_aggregated_output(self, output, names=None): | ||
raise NotImplementedError | ||
raise NotImplementedError("PanelGroupBy _wrap_aggregated_output") | ||
|
||
|
||
class NDArrayGroupBy(GroupBy): | ||
|
@@ -3172,7 +3172,7 @@ def _chop(self, sdata, slice_obj): | |
return sdata.iloc[slice_obj] | ||
|
||
def apply(self, f): | ||
raise NotImplementedError | ||
raise NotImplementedError("DataSplitter apply function") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. abstract |
||
|
||
|
||
class ArraySplitter(DataSplitter): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,7 +243,7 @@ def fillna(self, value, limit=None, inplace=False, downcast=None): | |
mask = isnull(self.values) | ||
if limit is not None: | ||
if self.ndim > 2: | ||
raise NotImplementedError | ||
raise NotImplementedError("fillna function not implemented for more than 2 dimensions") | ||
mask[mask.cumsum(self.ndim-1)>limit]=False | ||
|
||
value = self._try_fill(value) | ||
|
@@ -363,10 +363,10 @@ def convert(self, copy=True, **kwargs): | |
return [self.copy()] if copy else [self] | ||
|
||
def _can_hold_element(self, value): | ||
raise NotImplementedError() | ||
raise NotImplementedError("Block _can_hold_element function") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these 2 are abstract |
||
|
||
def _try_cast(self, value): | ||
raise NotImplementedError() | ||
raise NotImplementedError("Block _try_cast") | ||
|
||
def _try_cast_result(self, result, dtype=None): | ||
""" try to cast the result to our original type, | ||
|
@@ -1519,7 +1519,7 @@ def fillna(self, value, limit=None, | |
value = self._try_fill(value) | ||
if limit is not None: | ||
if self.ndim > 2: | ||
raise NotImplementedError | ||
raise NotImplementedError("fillna function not implemented for more than 2 dimensions") | ||
mask[mask.cumsum(self.ndim-1)>limit]=False | ||
|
||
np.putmask(values, mask, value) | ||
|
@@ -1741,7 +1741,7 @@ def interpolate(self, method='pad', axis=0, inplace=False, | |
def fillna(self, value, limit=None, inplace=False, downcast=None): | ||
# we may need to upcast our fill to match our dtype | ||
if limit is not None: | ||
raise NotImplementedError | ||
raise NotImplementedError("fillna currently implemented only for limit=None") | ||
if issubclass(self.dtype.type, np.floating): | ||
value = float(value) | ||
values = self.values if inplace else self.values.copy() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,10 +234,10 @@ cdef class IndexEngine: | |
self._ensure_mapping_populated() | ||
|
||
def _call_monotonic(self, values): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. both are abstract |
||
raise NotImplementedError | ||
raise NotImplementedError("IndexEngine _call_monotonic is not implemented") | ||
|
||
cdef _make_hash_table(self, n): | ||
raise NotImplementedError | ||
raise NotImplementedError("IndexEngine _make_hash_table is not implemented") | ||
|
||
cdef _check_type(self, object val): | ||
hash(val) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are both abstract as well