2015-11-29 16:46:32 +00:00
|
|
|
from nose.plugins.skip import SkipTest
|
2015-06-08 11:35:31 +00:00
|
|
|
|
2015-11-29 17:19:34 +00:00
|
|
|
from tqdm import tqdm
|
2016-01-09 20:57:25 +00:00
|
|
|
from tests_tqdm import with_setup, pretest, posttest, StringIO, closing
|
2015-06-08 11:35:31 +00:00
|
|
|
|
|
|
|
|
2016-01-09 20:57:25 +00:00
|
|
|
@with_setup(pretest, posttest)
|
2015-06-08 11:35:31 +00:00
|
|
|
def test_pandas():
|
2016-01-24 21:45:00 +00:00
|
|
|
""" Test pandas.DataFrame.groupby(0).progress_apply """
|
2015-11-29 16:46:32 +00:00
|
|
|
try:
|
2015-11-29 17:19:34 +00:00
|
|
|
from numpy.random import randint
|
2015-11-29 16:46:32 +00:00
|
|
|
from tqdm import tqdm_pandas
|
2015-11-29 17:19:34 +00:00
|
|
|
import pandas as pd
|
2015-11-29 16:46:32 +00:00
|
|
|
except:
|
|
|
|
raise SkipTest
|
2015-06-08 11:35:31 +00:00
|
|
|
|
2015-11-29 16:46:32 +00:00
|
|
|
with closing(StringIO()) as our_file:
|
2015-11-29 17:19:34 +00:00
|
|
|
df = pd.DataFrame(randint(0, 100, (1000, 6)))
|
|
|
|
tqdm_pandas(tqdm(file=our_file, leave=False, ascii=True))
|
2015-11-29 16:46:32 +00:00
|
|
|
df.groupby(0).progress_apply(lambda x: None)
|
2015-06-08 11:35:31 +00:00
|
|
|
|
2015-11-29 16:46:32 +00:00
|
|
|
our_file.seek(0)
|
2015-06-08 11:35:31 +00:00
|
|
|
|
2016-01-24 21:45:00 +00:00
|
|
|
# don't expect final output since no `leave` and
|
|
|
|
# high dynamic `miniters`
|
|
|
|
nexres = '100%|##########| 101/101'
|
|
|
|
if nexres in our_file.read():
|
|
|
|
our_file.seek(0)
|
|
|
|
raise AssertionError("\nDid not expect:\n{0}\nIn:{1}\n".format(
|
|
|
|
nexres, our_file.read()))
|
2015-06-08 11:35:31 +00:00
|
|
|
|
|
|
|
|
2016-01-09 20:57:25 +00:00
|
|
|
@with_setup(pretest, posttest)
|
2015-06-08 11:35:31 +00:00
|
|
|
def test_pandas_leave():
|
2016-01-24 21:45:00 +00:00
|
|
|
""" Test pandas with `leave=True` """
|
2015-11-29 16:46:32 +00:00
|
|
|
try:
|
2015-11-29 17:19:34 +00:00
|
|
|
from numpy.random import randint
|
2015-11-29 16:46:32 +00:00
|
|
|
from tqdm import tqdm_pandas
|
2015-11-29 17:19:34 +00:00
|
|
|
import pandas as pd
|
2015-11-29 16:46:32 +00:00
|
|
|
except:
|
|
|
|
raise SkipTest
|
2015-06-08 11:35:31 +00:00
|
|
|
|
2015-11-29 16:46:32 +00:00
|
|
|
with closing(StringIO()) as our_file:
|
2015-11-29 17:19:34 +00:00
|
|
|
df = pd.DataFrame(randint(0, 100, (1000, 6)))
|
|
|
|
tqdm_pandas(tqdm(file=our_file, leave=True, ascii=True))
|
2015-11-29 16:46:32 +00:00
|
|
|
df.groupby(0).progress_apply(lambda x: None)
|
2015-06-08 11:35:31 +00:00
|
|
|
|
2015-11-29 16:46:32 +00:00
|
|
|
our_file.seek(0)
|
2015-06-08 11:35:31 +00:00
|
|
|
|
2016-01-24 21:45:00 +00:00
|
|
|
exres = '100%|##########| 101/101'
|
|
|
|
if exres not in our_file.read():
|
2015-11-29 16:46:32 +00:00
|
|
|
our_file.seek(0)
|
2016-01-24 21:45:00 +00:00
|
|
|
raise AssertionError("\nExpected:\n{0}\nIn:{1}\n".format(
|
|
|
|
exres, our_file.read()))
|