Python pandas.core.common._not_none() Examples
The following are 4
code examples of pandas.core.common._not_none().
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.common
, or try the search function
.
Example #1
Source File: groupby.py From recruit with Apache License 2.0 | 4 votes |
def _concat_objects(self, keys, values, not_indexed_same=False): from pandas.core.reshape.concat import concat def reset_identity(values): # reset the identities of the components # of the values to prevent aliasing for v in com._not_none(*values): ax = v._get_axis(self.axis) ax._reset_identity() return values if not not_indexed_same: result = concat(values, axis=self.axis) ax = self._selected_obj._get_axis(self.axis) if isinstance(result, Series): result = result.reindex(ax) else: # this is a very unfortunate situation # we have a multi-index that is NOT lexsorted # and we have a result which is duplicated # we can't reindex, so we resort to this # GH 14776 if isinstance(ax, MultiIndex) and not ax.is_unique: indexer = algorithms.unique1d( result.index.get_indexer_for(ax.values)) result = result.take(indexer, axis=self.axis) else: result = result.reindex(ax, axis=self.axis) elif self.group_keys: values = reset_identity(values) if self.as_index: # possible MI return case group_keys = keys group_levels = self.grouper.levels group_names = self.grouper.names result = concat(values, axis=self.axis, keys=group_keys, levels=group_levels, names=group_names, sort=False) else: # GH5610, returns a MI, with the first level being a # range index keys = list(range(len(values))) result = concat(values, axis=self.axis, keys=keys) else: values = reset_identity(values) result = concat(values, axis=self.axis) if (isinstance(result, Series) and getattr(self, '_selection_name', None) is not None): result.name = self._selection_name return result
Example #2
Source File: base.py From vnpy_crypto with MIT License | 4 votes |
def _join_multi(self, other, how, return_indexers=True): from .multi import MultiIndex self_is_mi = isinstance(self, MultiIndex) other_is_mi = isinstance(other, MultiIndex) # figure out join names self_names = com._not_none(*self.names) other_names = com._not_none(*other.names) overlap = list(set(self_names) & set(other_names)) # need at least 1 in common, but not more than 1 if not len(overlap): raise ValueError("cannot join with no level specified and no " "overlapping names") if len(overlap) > 1: raise NotImplementedError("merging with more than one level " "overlap on a multi-index is not " "implemented") jl = overlap[0] # make the indices into mi's that match if not (self_is_mi and other_is_mi): flip_order = False if self_is_mi: self, other = other, self flip_order = True # flip if join method is right or left how = {'right': 'left', 'left': 'right'}.get(how, how) level = other.names.index(jl) result = self._join_level(other, level, how=how, return_indexers=return_indexers) if flip_order: if isinstance(result, tuple): return result[0], result[2], result[1] return result # 2 multi-indexes raise NotImplementedError("merging with both multi-indexes is not " "implemented")
Example #3
Source File: groupby.py From vnpy_crypto with MIT License | 4 votes |
def _concat_objects(self, keys, values, not_indexed_same=False): from pandas.core.reshape.concat import concat def reset_identity(values): # reset the identities of the components # of the values to prevent aliasing for v in com._not_none(*values): ax = v._get_axis(self.axis) ax._reset_identity() return values if not not_indexed_same: result = concat(values, axis=self.axis) ax = self._selected_obj._get_axis(self.axis) if isinstance(result, Series): result = result.reindex(ax) else: # this is a very unfortunate situation # we have a multi-index that is NOT lexsorted # and we have a result which is duplicated # we can't reindex, so we resort to this # GH 14776 if isinstance(ax, MultiIndex) and not ax.is_unique: indexer = algorithms.unique1d( result.index.get_indexer_for(ax.values)) result = result.take(indexer, axis=self.axis) else: result = result.reindex(ax, axis=self.axis) elif self.group_keys: values = reset_identity(values) if self.as_index: # possible MI return case group_keys = keys group_levels = self.grouper.levels group_names = self.grouper.names result = concat(values, axis=self.axis, keys=group_keys, levels=group_levels, names=group_names, sort=False) else: # GH5610, returns a MI, with the first level being a # range index keys = list(range(len(values))) result = concat(values, axis=self.axis, keys=keys) else: values = reset_identity(values) result = concat(values, axis=self.axis) if (isinstance(result, Series) and getattr(self, '_selection_name', None) is not None): result.name = self._selection_name return result
Example #4
Source File: groupby.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 4 votes |
def _concat_objects(self, keys, values, not_indexed_same=False): from pandas.core.reshape.concat import concat def reset_identity(values): # reset the identities of the components # of the values to prevent aliasing for v in com._not_none(*values): ax = v._get_axis(self.axis) ax._reset_identity() return values if not not_indexed_same: result = concat(values, axis=self.axis) ax = self._selected_obj._get_axis(self.axis) if isinstance(result, Series): result = result.reindex(ax) else: # this is a very unfortunate situation # we have a multi-index that is NOT lexsorted # and we have a result which is duplicated # we can't reindex, so we resort to this # GH 14776 if isinstance(ax, MultiIndex) and not ax.is_unique: indexer = algorithms.unique1d( result.index.get_indexer_for(ax.values)) result = result.take(indexer, axis=self.axis) else: result = result.reindex(ax, axis=self.axis) elif self.group_keys: values = reset_identity(values) if self.as_index: # possible MI return case group_keys = keys group_levels = self.grouper.levels group_names = self.grouper.names result = concat(values, axis=self.axis, keys=group_keys, levels=group_levels, names=group_names, sort=False) else: # GH5610, returns a MI, with the first level being a # range index keys = list(range(len(values))) result = concat(values, axis=self.axis, keys=keys) else: values = reset_identity(values) result = concat(values, axis=self.axis) if (isinstance(result, Series) and getattr(self, '_selection_name', None) is not None): result.name = self._selection_name return result