1import sys 2 3__author__ = "github.com/casperdcl" 4__all__ = ['tqdm_pandas'] 5 6 7def tqdm_pandas(tclass, **tqdm_kwargs): 8 """ 9 Registers the given `tqdm` instance with 10 `pandas.core.groupby.DataFrameGroupBy.progress_apply`. 11 """ 12 from tqdm import TqdmDeprecationWarning 13 14 if isinstance(tclass, type) or (getattr(tclass, '__name__', '').startswith( 15 'tqdm_')): # delayed adapter case 16 TqdmDeprecationWarning( 17 "Please use `tqdm.pandas(...)` instead of `tqdm_pandas(tqdm, ...)`.", 18 fp_write=getattr(tqdm_kwargs.get('file', None), 'write', sys.stderr.write)) 19 tclass.pandas(**tqdm_kwargs) 20 else: 21 TqdmDeprecationWarning( 22 "Please use `tqdm.pandas(...)` instead of `tqdm_pandas(tqdm(...))`.", 23 fp_write=getattr(tclass.fp, 'write', sys.stderr.write)) 24 type(tclass).pandas(deprecated_t=tclass) 25