Skip to content

Commit 7ee1faa

Browse files
committed
Remove unittest.mock
1 parent a59934d commit 7ee1faa

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

pandas/tests/frame/test_apply.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from datetime import datetime
33
from itertools import chain
44
import operator
5-
from unittest.mock import Mock
65
import warnings
76

87
import numpy as np
@@ -729,25 +728,40 @@ def test_apply_noreduction_tzaware_object(self):
729728

730729
def test_apply_function_runs_once(self):
731730
# https://github.com/pandas-dev/pandas/issues/30815
732-
non_reducing_mock = Mock(side_effect=lambda x: x)
733-
reducing_mock = Mock(return_value=1)
734731

735732
df = pd.DataFrame({"a": [1, 2, 3]})
733+
names = [] # Save row names function is applied to
736734

737-
# no reduction
738-
df.apply(non_reducing_mock, axis=1)
739-
assert non_reducing_mock.call_count == 3
735+
def reducing_function(row):
736+
names.append(row.name)
737+
738+
def non_reducing_function(row):
739+
names.append(row.name)
740+
return row
741+
742+
for func in [reducing_function, non_reducing_function]:
743+
del names[:]
740744

741-
# reduction
742-
df.apply(reducing_mock, axis=1)
743-
assert reducing_mock.call_count == 3
745+
df.apply(func, axis=1)
746+
assert names == list(df.index)
744747

745748
def test_applymap_function_runs_once(self):
746-
reducing_mock = Mock(return_value=1)
747749

748750
df = pd.DataFrame({"a": [1, 2, 3]})
749-
df.applymap(reducing_mock)
750-
assert reducing_mock.call_count == 3
751+
values = [] # Save values function is applied to
752+
753+
def reducing_function(val):
754+
values.append(val)
755+
756+
def non_reducing_function(val):
757+
values.append(val)
758+
return val
759+
760+
for func in [reducing_function, non_reducing_function]:
761+
del values[:]
762+
763+
df.applymap(func)
764+
assert values == df.a.to_list()
751765

752766

753767
class TestInferOutputShape:

0 commit comments

Comments
 (0)