_tqdm_pandas.py 888 B

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