summaryrefslogtreecommitdiffstats
path: root/tests/tests_pandas.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tests_pandas.py')
-rw-r--r--tests/tests_pandas.py54
1 files changed, 33 insertions, 21 deletions
diff --git a/tests/tests_pandas.py b/tests/tests_pandas.py
index 334a97c..09dff1e 100644
--- a/tests/tests_pandas.py
+++ b/tests/tests_pandas.py
@@ -4,6 +4,7 @@ from .tests_tqdm import StringIO, closing, importorskip, mark, skip
pytestmark = mark.slow
+np = importorskip('numpy')
random = importorskip('numpy.random')
rand = random.rand
randint = random.randint
@@ -39,8 +40,8 @@ def test_pandas_rolling_expanding():
our_file.seek(0)
if our_file.getvalue().count(exres) < 2:
our_file.seek(0)
- raise AssertionError("\nExpected:\n{0}\nIn:\n{1}\n".format(
- exres + " at least twice.", our_file.read()))
+ raise AssertionError(
+ f"\nExpected:\n{exres} at least twice.\nIn:\n{our_file.read()}\n")
def test_pandas_series():
@@ -62,10 +63,11 @@ def test_pandas_series():
our_file.seek(0)
if our_file.getvalue().count(exres) < 2:
our_file.seek(0)
- raise AssertionError("\nExpected:\n{0}\nIn:\n{1}\n".format(
- exres + " at least twice.", our_file.read()))
+ raise AssertionError(
+ f"\nExpected:\n{exres} at least twice.\nIn:\n{our_file.read()}\n")
+@mark.filterwarnings("ignore:DataFrame.applymap has been deprecated:FutureWarning")
def test_pandas_data_frame():
"""Test pandas.DataFrame.progress_apply and .progress_applymap"""
with closing(StringIO()) as our_file:
@@ -80,6 +82,12 @@ def test_pandas_data_frame():
res2 = df.applymap(task_func)
assert res1.equals(res2)
+ # map
+ if hasattr(df, 'map'): # pandas>=2.1.0
+ res1 = df.progress_map(task_func)
+ res2 = df.map(task_func)
+ assert res1.equals(res2)
+
# apply unhashable
res1 = []
df.progress_apply(res1.extend)
@@ -94,8 +102,8 @@ def test_pandas_data_frame():
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()))
+ raise AssertionError(
+ f"\nExpected:\n100% at least three times\nIn:\n{our_file.read()}\n")
# apply_map, apply axis=0, apply axis=1
expects = ['20000/20000', '200/200', '100/100']
@@ -103,10 +111,12 @@ def test_pandas_data_frame():
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()))
+ raise AssertionError(
+ f"\nExpected:\n{exres} at least once.\nIn:\n{our_file.read()}\n")
+@mark.filterwarnings(
+ "ignore:DataFrameGroupBy.apply operated on the grouping columns:DeprecationWarning")
def test_pandas_groupby_apply():
"""Test pandas.DataFrame.groupby(...).progress_apply"""
with closing(StringIO()) as our_file:
@@ -119,8 +129,8 @@ def test_pandas_groupby_apply():
dfs.groupby(['a']).progress_apply(lambda x: None)
df2 = df = pd.DataFrame({'a': randint(1, 8, 10000), 'b': rand(10000)})
- res1 = df2.groupby("a").apply(max)
- res2 = df2.groupby("a").progress_apply(max)
+ res1 = df2.groupby("a").apply(np.maximum.reduce)
+ res2 = df2.groupby("a").progress_apply(np.maximum.reduce)
assert res1.equals(res2)
our_file.seek(0)
@@ -130,8 +140,7 @@ def test_pandas_groupby_apply():
nexres = '100%|##########|'
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()))
+ raise AssertionError(f"\nDid not expect:\n{nexres}\nIn:{our_file.read()}\n")
with closing(StringIO()) as our_file:
tqdm.pandas(file=our_file, leave=True, ascii=True)
@@ -140,26 +149,28 @@ def test_pandas_groupby_apply():
dfs.loc[0] = [2, 1, 1]
dfs['d'] = 100
- expects = ['500/500', '1/1', '4/4', '2/2']
+ expects = ['500/500', '1/1', '4/4', '4/4']
dfs.groupby(dfs.index).progress_apply(lambda x: None)
dfs.groupby('d').progress_apply(lambda x: None)
- dfs.groupby(dfs.columns, axis=1).progress_apply(lambda x: None)
- dfs.groupby([2, 2, 1, 1], axis=1).progress_apply(lambda x: None)
+ dfs.T.groupby(dfs.columns).progress_apply(lambda x: None)
+ dfs.T.groupby([2, 2, 1, 1]).progress_apply(lambda x: None)
our_file.seek(0)
if our_file.read().count('100%') < 4:
our_file.seek(0)
- raise AssertionError("\nExpected:\n{0}\nIn:\n{1}\n".format(
- '100% at least four times', our_file.read()))
+ raise AssertionError(
+ f"\nExpected:\n100% at least four times\nIn:\n{our_file.read()}\n")
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()))
+ raise AssertionError(
+ f"\nExpected:\n{exres} at least once.\nIn:\n{our_file.read()}\n")
+@mark.filterwarnings(
+ "ignore:DataFrameGroupBy.apply operated on the grouping columns:DeprecationWarning")
def test_pandas_leave():
"""Test pandas with `leave=True`"""
with closing(StringIO()) as our_file:
@@ -172,8 +183,7 @@ def test_pandas_leave():
exres = '100%|##########| 100/100'
if exres not in our_file.read():
our_file.seek(0)
- raise AssertionError("\nExpected:\n{0}\nIn:{1}\n".format(
- exres, our_file.read()))
+ raise AssertionError(f"\nExpected:\n{exres}\nIn:{our_file.read()}\n")
def test_pandas_apply_args_deprecation():
@@ -195,6 +205,8 @@ def test_pandas_apply_args_deprecation():
"keyword arguments instead"))
+@mark.filterwarnings(
+ "ignore:DataFrameGroupBy.apply operated on the grouping columns:DeprecationWarning")
def test_pandas_deprecation():
"""Test bar object instance as argument deprecation"""
try: