Skip to content

Commit

Permalink
Add check for pandas builtin for progress apply
Browse files Browse the repository at this point in the history
Applied func will be checked against pandas internal builtins in order
to apply proper transformation, i.e max->amax

Closes:#697
  • Loading branch information
mikekutzma authored and casperdcl committed Nov 21, 2019
1 parent 83f2752 commit 80ade93
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tqdm/std.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,8 @@ def inner(df, func, *args, **kwargs):
" Use keyword arguments instead.",
fp_write=getattr(t.fp, 'write', sys.stderr.write))

func = df._is_builtin_func(func)

# Define bar updating wrapper
def wrapper(*args, **kwargs):
# update tbar correctly
Expand Down
7 changes: 6 additions & 1 deletion tqdm/tests/tests_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def task_func(x):
def test_pandas_groupby_apply():
"""Test pandas.DataFrame.groupby(...).progress_apply"""
try:
from numpy.random import randint
from numpy.random import randint, rand
import pandas as pd
except ImportError:
raise SkipTest
Expand All @@ -144,6 +144,11 @@ def test_pandas_groupby_apply():
dfs = pd.DataFrame(randint(0, 50, (500, 3)), columns=list('abc'))
dfs.groupby(['a']).progress_apply(lambda x: None)

df2 = df = pd.DataFrame(dict(a=randint(1, 8, 10000), b=rand(10000)))
res1 = df2.groupby("a").apply(max)
res2 = df2.groupby("a").progress_apply(max)
assert(res1.equals(res2))

our_file.seek(0)

# don't expect final output since no `leave` and
Expand Down

0 comments on commit 80ade93

Please sign in to comment.