def apply_series_generator(self) -> Tuple[ResType, "Index"]:
        series_gen = self.series_generator
        res_index = self.result_index

        results = {}

        if self.ignore_failures:
            successes = []
            for i, v in enumerate(series_gen):
                try:
                    results[i] = self.f(v)
                except Exception:
                    pass
                else:
                    successes.append(i)

            # so will work with MultiIndex
            if len(successes) < len(res_index):
                res_index = res_index.take(successes)

        else:
            with option_context("mode.chained_assignment", None):
                for i, v in enumerate(series_gen):
                    # ignore SettingWithCopy here in case the user mutates
                    results[i] = self.f(v)
                    if isinstance(results[i], ABCSeries):
                        # If we have a view on v, we need to make a copy because
                        #  series_generator will swap out the underlying data
                        results[i] = results[i].copy(deep=False)

        return results, res_index
Пример #2
0
    def apply_series_generator(self) -> Tuple[ResType, "Index"]:
        series_gen = self.series_generator
        res_index = self.result_index

        results = {}

        with option_context("mode.chained_assignment", None):
            for i, v in enumerate(series_gen):
                # ignore SettingWithCopy here in case the user mutates
                results[i] = self.f(v)
                if isinstance(results[i], ABCSeries):
                    # If we have a view on v, we need to make a copy because
                    #  series_generator will swap out the underlying area_data
                    results[i] = results[i].copy(deep=False)

        return results, res_index
Пример #3
0
    def apply_series_generator(self,
                               partial_result=None) -> Tuple[ResType, "Index"]:
        series_gen = self.series_generator
        res_index = self.result_index

        results = {}

        # If a partial result was already computed,
        # use it instead of running on the first element again
        series_gen_enumeration = enumerate(series_gen)
        if partial_result is not None:
            i, v = next(series_gen_enumeration)
            results[i] = partial_result

        if self.ignore_failures:
            successes = []
            for i, v in series_gen_enumeration:
                try:
                    results[i] = self.f(v)
                except Exception:
                    pass
                else:
                    successes.append(i)

            # so will work with MultiIndex
            if len(successes) < len(res_index):
                res_index = res_index.take(successes)

        else:
            for i, v in series_gen_enumeration:

                with option_context("mode.chained_assignment", None):
                    # ignore SettingWithCopy here in case the user mutates
                    results[i] = self.f(v)

                if isinstance(results[i], ABCSeries):
                    # If we have a view on v, we need to make a copy because
                    #  series_generator will swap out the underlying data
                    results[i] = results[i].copy(deep=False)

        return results, res_index