flake8, remove duplicate test

This commit is contained in:
Casper da Costa-Luis 2018-04-15 01:44:01 +01:00
parent bfa5bba470
commit b2228e1ee2
No known key found for this signature in database
GPG Key ID: 986B408043AE090D
2 changed files with 9 additions and 57 deletions

View File

@ -545,12 +545,11 @@ class tqdm(object):
from pandas.core.groupby import GroupBy
from pandas.core.groupby import PanelGroupBy
from pandas import Panel
# rolling and expanding since pandas 0.18.0
try:
# pandas>=0.18.0
from pandas.core.window import _Rolling_and_Expanding
skip_rolling_and_expanding = False
except ImportError: # pragma: no cover
skip_rolling_and_expanding = True
except ImportError: # pragma: no cover
_Rolling_and_Expanding = None
deprecated_t = [tkwargs.pop('deprecated_t', None)]
@ -574,7 +573,8 @@ class tqdm(object):
total = df.size
elif isinstance(df, Series):
total = len(df)
elif skip_rolling_and_expanding or not isinstance(df, _Rolling_and_Expanding):
elif _Rolling_and_Expanding is None or \
not isinstance(df, _Rolling_and_Expanding):
# DataFrame or Panel
axis = kwargs.get('axis', 0)
# when axis=0, total is shape[axis1]
@ -602,10 +602,7 @@ class tqdm(object):
# it seems `pandas apply` calls `func` twice
# on the first column/row to decide whether it can
# take a fast or slow code path; so stop when t.total==t.n
if t.total is not None:
t.update(n=1 if t.total and t.n < t.total else 0)
else:
t.update(1)
t.update(n=1 if not t.total or t.n < t.total else 0)
return func(*args, **kwargs)
# Apply the provided function (in **kwargs)
@ -636,8 +633,7 @@ class tqdm(object):
GroupBy.progress_aggregate = inner_generator('aggregate')
GroupBy.progress_transform = inner_generator('transform')
# Rolling and expanding
if not skip_rolling_and_expanding:
if _Rolling_and_Expanding is not None: # pragma: no cover
_Rolling_and_Expanding.progress_apply = inner_generator()
def __init__(self, iterable=None, desc=None, total=None, leave=True,

View File

@ -38,10 +38,10 @@ def test_pandas_rolling_expanding():
assert res1.equals(res2)
res3 = series.expanding(10).progress_apply(lambda x: 2)
res4 = series.expanding(10).apply(lambda x:2)
res4 = series.expanding(10).apply(lambda x: 2)
assert res3.equals(res4)
expects = ['114it'] #123-10+1
expects = ['114it'] # 123-10+1
for exres in expects:
our_file.seek(0)
if our_file.getvalue().count(exres) < 2:
@ -51,50 +51,6 @@ def test_pandas_rolling_expanding():
exres + " at least twice.", our_file.read()))
@with_setup(pretest, posttest)
def test_pandas_data_frame():
"""Test pandas.DataFrame.progress_apply and .progress_applymap"""
try:
from numpy.random import randint
import pandas as pd
except ImportError:
raise SkipTest
with closing(StringIO()) as our_file:
tqdm.pandas(file=our_file, leave=True, ascii=True)
df = pd.DataFrame(randint(0, 50, (100, 200)))
def task_func(x):
return x + 1
# applymap
res1 = df.progress_applymap(task_func)
res2 = df.applymap(task_func)
assert res1.equals(res2)
# apply
for axis in [0, 1]:
res3 = df.progress_apply(task_func, axis=axis)
res4 = df.apply(task_func, axis=axis)
assert res3.equals(res4)
our_file.seek(0)
if our_file.read().count('100%') < 3:
our_file.seek(0)
raise AssertionError("\nExpected:\n{0}\nIn:\n{1}\n".format(
'100% at least three times', our_file.read()))
# apply_map, apply axis=0, apply axis=1
expects = ['20000/20000', '200/200', '100/100']
for exres in expects:
our_file.seek(0)
if our_file.getvalue().count(exres) < 1:
our_file.seek(0)
raise AssertionError(
"\nExpected:\n{0}\nIn:\n {1}\n".format(
exres + " at least once.", our_file.read()))
@with_setup(pretest, posttest)
def test_pandas_series():
"""Test pandas.Series.progress_apply and .progress_map"""