Python pandas.compat.itervalues() Examples
The following are 26
code examples of pandas.compat.itervalues().
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.compat
, or try the search function
.
Example #1
Source File: nanops.py From recruit with Apache License 2.0 | 6 votes |
def __call__(self, f): @functools.wraps(f) def _f(*args, **kwargs): obj_iter = itertools.chain(args, compat.itervalues(kwargs)) if any(self.check(obj) for obj in obj_iter): msg = 'reduction operation {name!r} not allowed for this dtype' raise TypeError(msg.format(name=f.__name__.replace('nan', ''))) try: with np.errstate(invalid='ignore'): return f(*args, **kwargs) except ValueError as e: # we want to transform an object array # ValueError message to the more typical TypeError # e.g. this is normally a disallowed function on # object arrays that contain strings if is_object_dtype(args[0]): raise TypeError(e) raise return _f
Example #2
Source File: nanops.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def __call__(self, f): @functools.wraps(f) def _f(*args, **kwargs): obj_iter = itertools.chain(args, compat.itervalues(kwargs)) if any(self.check(obj) for obj in obj_iter): msg = 'reduction operation {name!r} not allowed for this dtype' raise TypeError(msg.format(name=f.__name__.replace('nan', ''))) try: with np.errstate(invalid='ignore'): return f(*args, **kwargs) except ValueError as e: # we want to transform an object array # ValueError message to the more typical TypeError # e.g. this is normally a disallowed function on # object arrays that contain strings if is_object_dtype(args[0]): raise TypeError(e) raise return _f
Example #3
Source File: concat.py From recruit with Apache License 2.0 | 6 votes |
def _get_series_result_type(result, objs=None): """ return appropriate class of Series concat input is either dict or array-like """ from pandas import SparseSeries, SparseDataFrame, DataFrame # concat Series with axis 1 if isinstance(result, dict): # concat Series with axis 1 if all(isinstance(c, (SparseSeries, SparseDataFrame)) for c in compat.itervalues(result)): return SparseDataFrame else: return DataFrame # otherwise it is a SingleBlockManager (axis = 0) if result._block.is_sparse: return SparseSeries else: return objs[0]._constructor
Example #4
Source File: nanops.py From vnpy_crypto with MIT License | 6 votes |
def __call__(self, f): @functools.wraps(f) def _f(*args, **kwargs): obj_iter = itertools.chain(args, compat.itervalues(kwargs)) if any(self.check(obj) for obj in obj_iter): msg = 'reduction operation {name!r} not allowed for this dtype' raise TypeError(msg.format(name=f.__name__.replace('nan', ''))) try: with np.errstate(invalid='ignore'): return f(*args, **kwargs) except ValueError as e: # we want to transform an object array # ValueError message to the more typical TypeError # e.g. this is normally a disallowed function on # object arrays that contain strings if is_object_dtype(args[0]): raise TypeError(e) raise return _f
Example #5
Source File: concat.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def _get_series_result_type(result, objs=None): """ return appropriate class of Series concat input is either dict or array-like """ # concat Series with axis 1 if isinstance(result, dict): # concat Series with axis 1 if all(is_sparse(c) for c in compat.itervalues(result)): from pandas.core.sparse.api import SparseDataFrame return SparseDataFrame else: from pandas.core.frame import DataFrame return DataFrame # otherwise it is a SingleBlockManager (axis = 0) if result._block.is_sparse: from pandas.core.sparse.api import SparseSeries return SparseSeries else: return objs[0]._constructor
Example #6
Source File: nanops.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def __call__(self, f): @functools.wraps(f) def _f(*args, **kwargs): obj_iter = itertools.chain(args, compat.itervalues(kwargs)) if any(self.check(obj) for obj in obj_iter): msg = 'reduction operation {name!r} not allowed for this dtype' raise TypeError(msg.format(name=f.__name__.replace('nan', ''))) try: with np.errstate(invalid='ignore'): return f(*args, **kwargs) except ValueError as e: # we want to transform an object array # ValueError message to the more typical TypeError # e.g. this is normally a disallowed function on # object arrays that contain strings if is_object_dtype(args[0]): raise TypeError(e) raise return _f
Example #7
Source File: concat.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def _get_series_result_type(result, objs=None): """ return appropriate class of Series concat input is either dict or array-like """ from pandas import SparseSeries, SparseDataFrame, DataFrame # concat Series with axis 1 if isinstance(result, dict): # concat Series with axis 1 if all(isinstance(c, (SparseSeries, SparseDataFrame)) for c in compat.itervalues(result)): return SparseDataFrame else: return DataFrame # otherwise it is a SingleBlockManager (axis = 0) if result._block.is_sparse: return SparseSeries else: return objs[0]._constructor
Example #8
Source File: nanops.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def __call__(self, f): @functools.wraps(f) def _f(*args, **kwargs): obj_iter = itertools.chain(args, compat.itervalues(kwargs)) if any(self.check(obj) for obj in obj_iter): msg = 'reduction operation {name!r} not allowed for this dtype' raise TypeError(msg.format(name=f.__name__.replace('nan', ''))) try: with np.errstate(invalid='ignore'): return f(*args, **kwargs) except ValueError as e: # we want to transform an object array # ValueError message to the more typical TypeError # e.g. this is normally a disallowed function on # object arrays that contain strings if is_object_dtype(args[0]): raise TypeError(e) raise return _f
Example #9
Source File: panel.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def _construct_return_type(self, result, axes=None): """ Return the type for the ndim of the result. """ ndim = getattr(result, 'ndim', None) # need to assume they are the same if ndim is None: if isinstance(result, dict): ndim = getattr(list(compat.itervalues(result))[0], 'ndim', 0) # have a dict, so top-level is +1 dim if ndim != 0: ndim += 1 # scalar if ndim == 0: return Series(result) # same as self elif self.ndim == ndim: # return the construction dictionary for these axes if axes is None: return self._constructor(result) return self._constructor(result, **self._construct_axes_dict()) # sliced elif self.ndim == ndim + 1: if axes is None: return self._constructor_sliced(result) return self._constructor_sliced( result, **self._extract_axes_for_slice(self, axes)) raise ValueError('invalid _construct_return_type [self->{self}] ' '[result->{result}]'.format(self=self, result=result))
Example #10
Source File: panel.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def _construct_return_type(self, result, axes=None): """ return the type for the ndim of the result """ ndim = getattr(result, 'ndim', None) # need to assume they are the same if ndim is None: if isinstance(result, dict): ndim = getattr(list(compat.itervalues(result))[0], 'ndim', 0) # have a dict, so top-level is +1 dim if ndim != 0: ndim += 1 # scalar if ndim == 0: return Series(result) # same as self elif self.ndim == ndim: # return the construction dictionary for these axes if axes is None: return self._constructor(result) return self._constructor(result, **self._construct_axes_dict()) # sliced elif self.ndim == ndim + 1: if axes is None: return self._constructor_sliced(result) return self._constructor_sliced( result, **self._extract_axes_for_slice(self, axes)) raise ValueError('invalid _construct_return_type [self->%s] ' '[result->%s]' % (self, result))
Example #11
Source File: test_packers.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_default_encoding(self): for frame in compat.itervalues(self.frame): result = frame.to_msgpack() expected = frame.to_msgpack(encoding='utf8') assert result == expected result = self.encode_decode(frame) assert_frame_equal(result, frame)
Example #12
Source File: test_packers.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_utf(self): # GH10581 for encoding in self.utf_encodings: for frame in compat.itervalues(self.frame): result = self.encode_decode(frame, encoding=encoding) assert_frame_equal(result, frame)
Example #13
Source File: panel.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _construct_return_type(self, result, axes=None): """ return the type for the ndim of the result """ ndim = getattr(result, 'ndim', None) # need to assume they are the same if ndim is None: if isinstance(result, dict): ndim = getattr(list(compat.itervalues(result))[0], 'ndim', 0) # have a dict, so top-level is +1 dim if ndim != 0: ndim += 1 # scalar if ndim == 0: return Series(result) # same as self elif self.ndim == ndim: # return the construction dictionary for these axes if axes is None: return self._constructor(result) return self._constructor(result, **self._construct_axes_dict()) # sliced elif self.ndim == ndim + 1: if axes is None: return self._constructor_sliced(result) return self._constructor_sliced( result, **self._extract_axes_for_slice(self, axes)) raise ValueError('invalid _construct_return_type [self->%s] ' '[result->%s]' % (self, result))
Example #14
Source File: panel.py From recruit with Apache License 2.0 | 5 votes |
def _construct_return_type(self, result, axes=None): """ Return the type for the ndim of the result. """ ndim = getattr(result, 'ndim', None) # need to assume they are the same if ndim is None: if isinstance(result, dict): ndim = getattr(list(compat.itervalues(result))[0], 'ndim', 0) # have a dict, so top-level is +1 dim if ndim != 0: ndim += 1 # scalar if ndim == 0: return Series(result) # same as self elif self.ndim == ndim: # return the construction dictionary for these axes if axes is None: return self._constructor(result) return self._constructor(result, **self._construct_axes_dict()) # sliced elif self.ndim == ndim + 1: if axes is None: return self._constructor_sliced(result) return self._constructor_sliced( result, **self._extract_axes_for_slice(self, axes)) raise ValueError('invalid _construct_return_type [self->{self}] ' '[result->{result}]'.format(self=self, result=result))
Example #15
Source File: data.py From Computable with MIT License | 5 votes |
def get_quote_yahoo(symbols): """ Get current yahoo quote Returns a DataFrame """ if isinstance(symbols, compat.string_types): sym_list = symbols else: sym_list = '+'.join(symbols) # for codes see: http://www.gummy-stuff.org/Yahoo-data.htm request = ''.join(compat.itervalues(_yahoo_codes)) # code request string header = list(_yahoo_codes.keys()) data = defaultdict(list) url_str = _YAHOO_QUOTE_URL + 's=%s&f=%s' % (sym_list, request) with urlopen(url_str) as url: lines = url.readlines() for line in lines: fields = line.decode('utf-8').strip().split(',') for i, field in enumerate(fields): if field[-2:] == '%"': v = float(field.strip('"%')) elif field[0] == '"': v = field.strip('"') else: try: v = float(field) except ValueError: v = np.nan data[header[i]].append(v) idx = data.pop('symbol') return DataFrame(data, index=idx)
Example #16
Source File: nanops.py From Computable with MIT License | 5 votes |
def __call__(self, f): @functools.wraps(f) def _f(*args, **kwargs): obj_iter = itertools.chain(args, compat.itervalues(kwargs)) if any(self.check(obj) for obj in obj_iter): raise TypeError('reduction operation {0!r} not allowed for ' 'this dtype'.format(f.__name__.replace('nan', ''))) return f(*args, **kwargs) return _f
Example #17
Source File: panel.py From Computable with MIT License | 5 votes |
def _construct_return_type(self, result, axes=None, **kwargs): """ return the type for the ndim of the result """ ndim = getattr(result,'ndim',None) # need to assume they are the same if ndim is None: if isinstance(result,dict): ndim = getattr(list(compat.itervalues(result))[0],'ndim',None) # a saclar result if ndim is None: ndim = 0 # have a dict, so top-level is +1 dim else: ndim += 1 # scalar if ndim == 0: return Series(result) # same as self elif self.ndim == ndim: """ return the construction dictionary for these axes """ if axes is None: return self._constructor(result) return self._constructor(result, **self._construct_axes_dict()) # sliced elif self.ndim == ndim + 1: if axes is None: return self._constructor_sliced(result) return self._constructor_sliced( result, **self._extract_axes_for_slice(self, axes)) raise PandasError('invalid _construct_return_type [self->%s] ' '[result->%s]' % (self, result))
Example #18
Source File: panel.py From Computable with MIT License | 5 votes |
def __set__(self, obj, value): value = _ensure_index(value) if isinstance(value, MultiIndex): raise NotImplementedError for v in compat.itervalues(obj._frames): setattr(v, self.frame_attr, value) setattr(obj, self.cache_field, value)
Example #19
Source File: panel.py From vnpy_crypto with MIT License | 5 votes |
def _construct_return_type(self, result, axes=None): """ return the type for the ndim of the result """ ndim = getattr(result, 'ndim', None) # need to assume they are the same if ndim is None: if isinstance(result, dict): ndim = getattr(list(compat.itervalues(result))[0], 'ndim', 0) # have a dict, so top-level is +1 dim if ndim != 0: ndim += 1 # scalar if ndim == 0: return Series(result) # same as self elif self.ndim == ndim: # return the construction dictionary for these axes if axes is None: return self._constructor(result) return self._constructor(result, **self._construct_axes_dict()) # sliced elif self.ndim == ndim + 1: if axes is None: return self._constructor_sliced(result) return self._constructor_sliced( result, **self._extract_axes_for_slice(self, axes)) raise ValueError('invalid _construct_return_type [self->{self}] ' '[result->{result}]'.format(self=self, result=result))
Example #20
Source File: test_packers.py From vnpy_crypto with MIT License | 5 votes |
def test_default_encoding(self): for frame in compat.itervalues(self.frame): result = frame.to_msgpack() expected = frame.to_msgpack(encoding='utf8') assert result == expected result = self.encode_decode(frame) assert_frame_equal(result, frame)
Example #21
Source File: test_packers.py From vnpy_crypto with MIT License | 5 votes |
def test_utf(self): # GH10581 for encoding in self.utf_encodings: for frame in compat.itervalues(self.frame): result = self.encode_decode(frame, encoding=encoding) assert_frame_equal(result, frame)
Example #22
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)
Example #23
Source File: groupby.py From Splunking-Crime with GNU Affero General Public License v3.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(_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 %s' % 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 isinstance(list(compat.itervalues(results))[0], DataFrame): # let higher level handle if _level: return results return list(compat.itervalues(results))[0] return DataFrame(results, columns=columns)
Example #24
Source File: groupby.py From vnpy_crypto with MIT License | 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 %s' % 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 isinstance(list(compat.itervalues(results))[0], DataFrame): # let higher level handle if _level: return results return list(compat.itervalues(results))[0] return DataFrame(results, columns=columns)
Example #25
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 #26
Source File: groupby.py From elasticintel with GNU General Public License v3.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(_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 %s' % 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 isinstance(list(compat.itervalues(results))[0], DataFrame): # let higher level handle if _level: return results return list(compat.itervalues(results))[0] return DataFrame(results, columns=columns)