|
39 | 39 | from pandas.core.dtypes.missing import isna, notna, _maybe_fill |
40 | 40 |
|
41 | 41 | from pandas.core.common import (_values_from_object, AbstractMethodError, |
42 | | - _default_index) |
| 42 | + _default_index, _not_none, _get_callable_name, |
| 43 | + _asarray_tuplesafe) |
43 | 44 |
|
44 | 45 | from pandas.core.base import (PandasObject, SelectionMixin, GroupByError, |
45 | 46 | DataError, SpecificationError) |
|
60 | 61 | from pandas.util._validators import validate_kwargs |
61 | 62 |
|
62 | 63 | import pandas.core.algorithms as algorithms |
63 | | -import pandas.core.common as com |
64 | 64 | from pandas.core.config import option_context |
65 | 65 |
|
66 | 66 | from pandas.plotting._core import boxplot_frame_groupby |
@@ -877,10 +877,9 @@ def _concat_objects(self, keys, values, not_indexed_same=False): |
877 | 877 | def reset_identity(values): |
878 | 878 | # reset the identities of the components |
879 | 879 | # of the values to prevent aliasing |
880 | | - for v in values: |
881 | | - if v is not None: |
882 | | - ax = v._get_axis(self.axis) |
883 | | - ax._reset_identity() |
| 880 | + for v in _not_none(*values): |
| 881 | + ax = v._get_axis(self.axis) |
| 882 | + ax._reset_identity() |
884 | 883 | return values |
885 | 884 |
|
886 | 885 | if not not_indexed_same: |
@@ -1806,7 +1805,7 @@ def apply(self, f, data, axis=0): |
1806 | 1805 | group_keys = self._get_group_keys() |
1807 | 1806 |
|
1808 | 1807 | # oh boy |
1809 | | - f_name = com._get_callable_name(f) |
| 1808 | + f_name = _get_callable_name(f) |
1810 | 1809 | if (f_name not in _plotting_methods and |
1811 | 1810 | hasattr(splitter, 'fast_apply') and axis == 0): |
1812 | 1811 | try: |
@@ -2533,7 +2532,7 @@ def __init__(self, index, grouper=None, obj=None, name=None, level=None, |
2533 | 2532 | self.grouper = self.obj[self.name] |
2534 | 2533 |
|
2535 | 2534 | elif isinstance(self.grouper, (list, tuple)): |
2536 | | - self.grouper = com._asarray_tuplesafe(self.grouper) |
| 2535 | + self.grouper = _asarray_tuplesafe(self.grouper) |
2537 | 2536 |
|
2538 | 2537 | # a passed Categorical |
2539 | 2538 | elif is_categorical_dtype(self.grouper): |
@@ -2739,7 +2738,7 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True, |
2739 | 2738 | if not any_callable and not all_in_columns_index and \ |
2740 | 2739 | not any_arraylike and not any_groupers and \ |
2741 | 2740 | match_axis_length and level is None: |
2742 | | - keys = [com._asarray_tuplesafe(keys)] |
| 2741 | + keys = [_asarray_tuplesafe(keys)] |
2743 | 2742 |
|
2744 | 2743 | if isinstance(level, (tuple, list)): |
2745 | 2744 | if key is None: |
@@ -3028,7 +3027,7 @@ def _aggregate_multiple_funcs(self, arg, _level): |
3028 | 3027 | columns.append(f) |
3029 | 3028 | else: |
3030 | 3029 | # protect against callables without names |
3031 | | - columns.append(com._get_callable_name(f)) |
| 3030 | + columns.append(_get_callable_name(f)) |
3032 | 3031 | arg = lzip(columns, arg) |
3033 | 3032 |
|
3034 | 3033 | results = {} |
@@ -3686,14 +3685,13 @@ def _wrap_applied_output(self, keys, values, not_indexed_same=False): |
3686 | 3685 | key_names = self.grouper.names |
3687 | 3686 |
|
3688 | 3687 | # GH12824. |
3689 | | - def first_non_None_value(values): |
| 3688 | + def first_not_none(values): |
3690 | 3689 | try: |
3691 | | - v = next(v for v in values if v is not None) |
| 3690 | + return next(_not_none(*values)) |
3692 | 3691 | except StopIteration: |
3693 | 3692 | return None |
3694 | | - return v |
3695 | 3693 |
|
3696 | | - v = first_non_None_value(values) |
| 3694 | + v = first_not_none(values) |
3697 | 3695 |
|
3698 | 3696 | if v is None: |
3699 | 3697 | # GH9684. If all values are None, then this will throw an error. |
@@ -3726,7 +3724,7 @@ def first_non_None_value(values): |
3726 | 3724 | key_index = None |
3727 | 3725 |
|
3728 | 3726 | # make Nones an empty object |
3729 | | - v = first_non_None_value(values) |
| 3727 | + v = first_not_none(values) |
3730 | 3728 | if v is None: |
3731 | 3729 | return DataFrame() |
3732 | 3730 | elif isinstance(v, NDFrame): |
|
0 commit comments