def __call__( self, data: DataFrame, groupby: GroupBy, orient: str, scales: dict[str, Scale], ) -> DataFrame: boot_kws = {"n_boot": self.n_boot, "seed": self.seed} engine = EstimateAggregator(self.func, self.errorbar, **boot_kws) var = {"x": "y", "y": "x"}.get(orient) res = (groupby.apply( data, self._process, var, engine).dropna(subset=["x", "y"]).reset_index(drop=True)) res = res.fillna({f"{var}min": res[var], f"{var}max": res[var]}) return res
def __call__(self, data, groupby, orient, scales): # TODO better to do this as an isinstance check? # We are only asking about Nominal scales now, # but presumably would apply to Ordinal too? scale_type = scales[orient].__class__.__name__.lower() grouping_vars = [v for v in data if v in groupby.order] if not grouping_vars or self.common_bins is True: bin_kws = self._define_bin_params(data, orient, scale_type) data = groupby.apply(data, self._eval, orient, bin_kws) else: if self.common_bins is False: bin_groupby = GroupBy(grouping_vars) else: bin_groupby = GroupBy(self.common_bins) data = bin_groupby.apply( data, self._get_bins_and_eval, orient, groupby, scale_type, ) # TODO Make this an option? # (This needs to be tested if enabled, and maybe should be in _eval) # other = {"x": "y", "y": "x"}[orient] # data = data[data[other] > 0] if not grouping_vars or self.common_norm is True: data = self._normalize(data, orient) else: if self.common_norm is False: norm_grouper = grouping_vars else: norm_grouper = self.common_norm normalize = partial(self._normalize, orient=orient) data = GroupBy(norm_grouper).apply(data, normalize) return data
def __call__(self, data, groupby, orient, scales): scale_type = scales[orient].scale_type grouping_vars = [v for v in data if v in groupby.order] if not grouping_vars or self.common_bins is True: bin_kws = self._define_bin_params(data, orient, scale_type) data = groupby.apply(data, self._eval, orient, bin_kws) else: if self.common_bins is False: bin_groupby = GroupBy(grouping_vars) else: bin_groupby = GroupBy(self.common_bins) data = bin_groupby.apply( data, self._get_bins_and_eval, orient, groupby, scale_type, ) # TODO Make this an option? # (This needs to be tested if enabled, and maybe should be in _eval) # other = {"x": "y", "y": "x"}[orient] # data = data[data[other] > 0] if not grouping_vars or self.common_norm is True: data = self._normalize(data, orient) else: if self.common_norm is False: norm_grouper = grouping_vars else: norm_grouper = self.common_norm normalize = partial(self._normalize, orient=orient) data = GroupBy(norm_grouper).apply(data, normalize) return data
def __call__(self, data: DataFrame, groupby: GroupBy, orient: str) -> DataFrame: other = {"x": "y", "y": "x"}[orient] return groupby.apply(data, self._norm, other)