Parameters ---------- df : (DataFrame|Series)[GroupBy] Data (may be grouped). func : function To be applied on the (grouped) data. **kwargs : optional Trans
(df, func, *args, **kwargs)
| 848 | |
| 849 | def inner_generator(df_function='apply'): |
| 850 | def inner(df, func, *args, **kwargs): |
| 851 | """ |
| 852 | Parameters |
| 853 | ---------- |
| 854 | df : (DataFrame|Series)[GroupBy] |
| 855 | Data (may be grouped). |
| 856 | func : function |
| 857 | To be applied on the (grouped) data. |
| 858 | **kwargs : optional |
| 859 | Transmitted to `df.apply()`. |
| 860 | """ |
| 861 | |
| 862 | # Precompute total iterations |
| 863 | total = tqdm_kwargs.pop("total", getattr(df, 'ngroups', None)) |
| 864 | if total is None: # not grouped |
| 865 | if df_function == 'applymap': |
| 866 | total = df.size |
| 867 | elif isinstance(df, Series): |
| 868 | total = len(df) |
| 869 | elif (_Rolling_and_Expanding is None or |
| 870 | not isinstance(df, _Rolling_and_Expanding)): |
| 871 | # DataFrame or Panel |
| 872 | axis = kwargs.get('axis', 0) |
| 873 | if axis == 'index': |
| 874 | axis = 0 |
| 875 | elif axis == 'columns': |
| 876 | axis = 1 |
| 877 | # when axis=0, total is shape[axis1] |
| 878 | total = df.size // df.shape[axis] |
| 879 | |
| 880 | # Init bar |
| 881 | if deprecated_t[0] is not None: |
| 882 | t = deprecated_t[0] |
| 883 | deprecated_t[0] = None |
| 884 | else: |
| 885 | t = cls(total=total, **tqdm_kwargs) |
| 886 | |
| 887 | if len(args) > 0: |
| 888 | # *args intentionally not supported (see #244, #299) |
| 889 | TqdmDeprecationWarning( |
| 890 | "Except func, normal arguments are intentionally" + |
| 891 | " not supported by" + |
| 892 | " `(DataFrame|Series|GroupBy).progress_apply`." + |
| 893 | " Use keyword arguments instead.", |
| 894 | fp_write=getattr(t.fp, 'write', sys.stderr.write)) |
| 895 | |
| 896 | try: # pandas>=1.3.0,<3.0 |
| 897 | from pandas.core.common import is_builtin_func |
| 898 | except ImportError: # pandas<1.3.0 |
| 899 | is_builtin_func = getattr(df, '_is_builtin_func', lambda f: f) |
| 900 | try: |
| 901 | func = is_builtin_func(func) |
| 902 | except TypeError: |
| 903 | pass |
| 904 | |
| 905 | # Define bar updating wrapper |
| 906 | def wrapper(*args, **kwargs): |
| 907 | # update tbar correctly |
nothing calls this directly
no test coverage detected