Python pandas.core.base.SpecificationError() Examples
The following are 10
code examples of pandas.core.base.SpecificationError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pandas.core.base
, or try the search function
.
Example #1
Source File: test_window.py From recruit with Apache License 2.0 | 5 votes |
def test_agg_nested_dicts(self): # API change for disallowing these types of nested dicts df = DataFrame({'A': range(5), 'B': range(0, 10, 2)}) r = df.rolling(window=3) def f(): r.aggregate({'r1': {'A': ['mean', 'sum']}, 'r2': {'B': ['mean', 'sum']}}) pytest.raises(SpecificationError, f) expected = concat([r['A'].mean(), r['A'].std(), r['B'].mean(), r['B'].std()], axis=1) expected.columns = pd.MultiIndex.from_tuples([('ra', 'mean'), ( 'ra', 'std'), ('rb', 'mean'), ('rb', 'std')]) with catch_warnings(record=True): warnings.simplefilter("ignore", FutureWarning) result = r[['A', 'B']].agg({'A': {'ra': ['mean', 'std']}, 'B': {'rb': ['mean', 'std']}}) tm.assert_frame_equal(result, expected, check_like=True) with catch_warnings(record=True): warnings.simplefilter("ignore", FutureWarning) result = r.agg({'A': {'ra': ['mean', 'std']}, 'B': {'rb': ['mean', 'std']}}) expected.columns = pd.MultiIndex.from_tuples([('A', 'ra', 'mean'), ( 'A', 'ra', 'std'), ('B', 'rb', 'mean'), ('B', 'rb', 'std')]) tm.assert_frame_equal(result, expected, check_like=True)
Example #2
Source File: test_aggregate.py From recruit with Apache License 2.0 | 5 votes |
def test_agg_multiple_functions_too_many_lambdas(df): grouped = df.groupby('A') funcs = ['mean', lambda x: x.mean(), lambda x: x.std()] msg = 'Function names must be unique, found multiple named <lambda>' with pytest.raises(SpecificationError, match=msg): grouped.agg(funcs)
Example #3
Source File: test_window.py From vnpy_crypto with MIT License | 5 votes |
def test_agg_nested_dicts(self): # API change for disallowing these types of nested dicts df = DataFrame({'A': range(5), 'B': range(0, 10, 2)}) r = df.rolling(window=3) def f(): r.aggregate({'r1': {'A': ['mean', 'sum']}, 'r2': {'B': ['mean', 'sum']}}) pytest.raises(SpecificationError, f) expected = concat([r['A'].mean(), r['A'].std(), r['B'].mean(), r['B'].std()], axis=1) expected.columns = pd.MultiIndex.from_tuples([('ra', 'mean'), ( 'ra', 'std'), ('rb', 'mean'), ('rb', 'std')]) with catch_warnings(record=True): result = r[['A', 'B']].agg({'A': {'ra': ['mean', 'std']}, 'B': {'rb': ['mean', 'std']}}) tm.assert_frame_equal(result, expected, check_like=True) with catch_warnings(record=True): result = r.agg({'A': {'ra': ['mean', 'std']}, 'B': {'rb': ['mean', 'std']}}) expected.columns = pd.MultiIndex.from_tuples([('A', 'ra', 'mean'), ( 'A', 'ra', 'std'), ('B', 'rb', 'mean'), ('B', 'rb', 'std')]) tm.assert_frame_equal(result, expected, check_like=True)
Example #4
Source File: test_window.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_agg_nested_dicts(self): # API change for disallowing these types of nested dicts df = DataFrame({'A': range(5), 'B': range(0, 10, 2)}) r = df.rolling(window=3) def f(): r.aggregate({'r1': {'A': ['mean', 'sum']}, 'r2': {'B': ['mean', 'sum']}}) pytest.raises(SpecificationError, f) expected = concat([r['A'].mean(), r['A'].std(), r['B'].mean(), r['B'].std()], axis=1) expected.columns = pd.MultiIndex.from_tuples([('ra', 'mean'), ( 'ra', 'std'), ('rb', 'mean'), ('rb', 'std')]) with catch_warnings(record=True): warnings.simplefilter("ignore", FutureWarning) result = r[['A', 'B']].agg({'A': {'ra': ['mean', 'std']}, 'B': {'rb': ['mean', 'std']}}) tm.assert_frame_equal(result, expected, check_like=True) with catch_warnings(record=True): warnings.simplefilter("ignore", FutureWarning) result = r.agg({'A': {'ra': ['mean', 'std']}, 'B': {'rb': ['mean', 'std']}}) expected.columns = pd.MultiIndex.from_tuples([('A', 'ra', 'mean'), ( 'A', 'ra', 'std'), ('B', 'rb', 'mean'), ('B', 'rb', 'std')]) tm.assert_frame_equal(result, expected, check_like=True)
Example #5
Source File: test_aggregate.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_agg_multiple_functions_too_many_lambdas(df): grouped = df.groupby('A') funcs = ['mean', lambda x: x.mean(), lambda x: x.std()] msg = 'Function names must be unique, found multiple named <lambda>' with pytest.raises(SpecificationError, match=msg): grouped.agg(funcs)
Example #6
Source File: test_window.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_agg_nested_dicts(self): # API change for disallowing these types of nested dicts df = DataFrame({'A': range(5), 'B': range(0, 10, 2)}) r = df.rolling(window=3) def f(): r.aggregate({'r1': {'A': ['mean', 'sum']}, 'r2': {'B': ['mean', 'sum']}}) pytest.raises(SpecificationError, f) expected = pd.concat([r['A'].mean(), r['A'].std(), r['B'].mean(), r['B'].std()], axis=1) expected.columns = pd.MultiIndex.from_tuples([('ra', 'mean'), ( 'ra', 'std'), ('rb', 'mean'), ('rb', 'std')]) with catch_warnings(record=True): result = r[['A', 'B']].agg({'A': {'ra': ['mean', 'std']}, 'B': {'rb': ['mean', 'std']}}) tm.assert_frame_equal(result, expected, check_like=True) with catch_warnings(record=True): result = r.agg({'A': {'ra': ['mean', 'std']}, 'B': {'rb': ['mean', 'std']}}) expected.columns = pd.MultiIndex.from_tuples([('A', 'ra', 'mean'), ( 'A', 'ra', 'std'), ('B', 'rb', 'mean'), ('B', 'rb', 'std')]) tm.assert_frame_equal(result, expected, check_like=True)
Example #7
Source File: test_window.py From coffeegrindsize with MIT License | 5 votes |
def test_agg_nested_dicts(self): # API change for disallowing these types of nested dicts df = DataFrame({'A': range(5), 'B': range(0, 10, 2)}) r = df.rolling(window=3) def f(): r.aggregate({'r1': {'A': ['mean', 'sum']}, 'r2': {'B': ['mean', 'sum']}}) pytest.raises(SpecificationError, f) expected = concat([r['A'].mean(), r['A'].std(), r['B'].mean(), r['B'].std()], axis=1) expected.columns = pd.MultiIndex.from_tuples([('ra', 'mean'), ( 'ra', 'std'), ('rb', 'mean'), ('rb', 'std')]) with catch_warnings(record=True): warnings.simplefilter("ignore", FutureWarning) result = r[['A', 'B']].agg({'A': {'ra': ['mean', 'std']}, 'B': {'rb': ['mean', 'std']}}) tm.assert_frame_equal(result, expected, check_like=True) with catch_warnings(record=True): warnings.simplefilter("ignore", FutureWarning) result = r.agg({'A': {'ra': ['mean', 'std']}, 'B': {'rb': ['mean', 'std']}}) expected.columns = pd.MultiIndex.from_tuples([('A', 'ra', 'mean'), ( 'A', 'ra', 'std'), ('B', 'rb', 'mean'), ('B', 'rb', 'std')]) tm.assert_frame_equal(result, expected, check_like=True)
Example #8
Source File: test_window.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_agg_nested_dicts(self): # API change for disallowing these types of nested dicts df = DataFrame({'A': range(5), 'B': range(0, 10, 2)}) r = df.rolling(window=3) def f(): r.aggregate({'r1': {'A': ['mean', 'sum']}, 'r2': {'B': ['mean', 'sum']}}) pytest.raises(SpecificationError, f) expected = concat([r['A'].mean(), r['A'].std(), r['B'].mean(), r['B'].std()], axis=1) expected.columns = pd.MultiIndex.from_tuples([('ra', 'mean'), ( 'ra', 'std'), ('rb', 'mean'), ('rb', 'std')]) with catch_warnings(record=True): result = r[['A', 'B']].agg({'A': {'ra': ['mean', 'std']}, 'B': {'rb': ['mean', 'std']}}) tm.assert_frame_equal(result, expected, check_like=True) with catch_warnings(record=True): result = r.agg({'A': {'ra': ['mean', 'std']}, 'B': {'rb': ['mean', 'std']}}) expected.columns = pd.MultiIndex.from_tuples([('A', 'ra', 'mean'), ( 'A', 'ra', 'std'), ('B', 'rb', 'mean'), ('B', 'rb', 'std')]) tm.assert_frame_equal(result, expected, check_like=True)
Example #9
Source File: generic.py From recruit with Apache License 2.0 | 4 votes |
def _aggregate_multiple_funcs(self, arg, _level): if isinstance(arg, dict): # show the deprecation, but only if we # have not shown a higher level one # GH 15931 if isinstance(self._selected_obj, Series) and _level <= 1: warnings.warn( ("using a dict on a Series for aggregation\n" "is deprecated and will be removed in a future " "version"), FutureWarning, stacklevel=3) columns = list(arg.keys()) arg = list(arg.items()) elif any(isinstance(x, (tuple, list)) for x in arg): arg = [(x, x) if not isinstance(x, (tuple, list)) else x for x in arg] # indicated column order columns = lzip(*arg)[0] else: # list of functions / function names columns = [] for f in arg: if isinstance(f, compat.string_types): columns.append(f) else: # protect against callables without names columns.append(com.get_callable_name(f)) arg = lzip(columns, arg) results = {} for name, func in arg: obj = self if name in results: raise SpecificationError( 'Function names must be unique, found multiple named ' '{}'.format(name)) # reset the cache so that we # only include the named selection if name in self._selected_obj: obj = copy.copy(obj) obj._reset_cache() obj._selection = name results[name] = obj.aggregate(func) if any(isinstance(x, DataFrame) for x in compat.itervalues(results)): # let higher level handle if _level: return results return DataFrame(results, columns=columns)
Example #10
Source File: generic.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 4 votes |
def _aggregate_multiple_funcs(self, arg, _level): if isinstance(arg, dict): # show the deprecation, but only if we # have not shown a higher level one # GH 15931 if isinstance(self._selected_obj, Series) and _level <= 1: warnings.warn( ("using a dict on a Series for aggregation\n" "is deprecated and will be removed in a future " "version"), FutureWarning, stacklevel=3) columns = list(arg.keys()) arg = list(arg.items()) elif any(isinstance(x, (tuple, list)) for x in arg): arg = [(x, x) if not isinstance(x, (tuple, list)) else x for x in arg] # indicated column order columns = lzip(*arg)[0] else: # list of functions / function names columns = [] for f in arg: if isinstance(f, compat.string_types): columns.append(f) else: # protect against callables without names columns.append(com.get_callable_name(f)) arg = lzip(columns, arg) results = {} for name, func in arg: obj = self if name in results: raise SpecificationError( 'Function names must be unique, found multiple named ' '{}'.format(name)) # reset the cache so that we # only include the named selection if name in self._selected_obj: obj = copy.copy(obj) obj._reset_cache() obj._selection = name results[name] = obj.aggregate(func) if any(isinstance(x, DataFrame) for x in compat.itervalues(results)): # let higher level handle if _level: return results return DataFrame(results, columns=columns)