Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace applymap with map #226

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions ffn/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,4 @@ def as_format(item, format_str=".2f"):
"""
Map a format string over a pandas object.
"""
if isinstance(item, pd.Series):
return item.map(lambda x: format(x, format_str))
elif isinstance(item, pd.DataFrame):
return item.applymap(lambda x: format(x, format_str))
return item.map(lambda x: format(x, format_str))
8 changes: 4 additions & 4 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def test_random_weights():
for i in df.index:
df.loc[i] = ffn.random_weights(n, bounds, tot)
assert df.sum(axis=1).apply(lambda x: np.round(x, 4) == tot).all()
assert df.applymap(lambda x: (x >= low and x <= high)).all().all()
assert df.map(lambda x: (x >= low and x <= high)).all().all()

n = 4
bounds = (0.0, 0.25)
Expand All @@ -465,7 +465,7 @@ def test_random_weights():
df.loc[i] = ffn.random_weights(n, bounds, tot)
assert df.sum(axis=1).apply(lambda x: np.round(x, 4) == tot).all()
assert (
df.applymap(lambda x: (np.round(x, 2) >= low and np.round(x, 2) <= high))
df.map(lambda x: (np.round(x, 2) >= low and np.round(x, 2) <= high))
.all()
.all()
)
Expand All @@ -481,7 +481,7 @@ def test_random_weights():
df.loc[i] = ffn.random_weights(n, bounds, tot)
assert df.sum(axis=1).apply(lambda x: np.round(x, 4) == tot).all()
assert (
df.applymap(lambda x: (np.round(x, 2) >= low and np.round(x, 2) <= high))
df.map(lambda x: (np.round(x, 2) >= low and np.round(x, 2) <= high))
.all()
.all()
)
Expand All @@ -497,7 +497,7 @@ def test_random_weights():
df.loc[i] = ffn.random_weights(n, bounds, tot)
assert df.sum(axis=1).apply(lambda x: np.round(x, 4) == tot).all()
assert (
df.applymap(lambda x: (np.round(x, 2) >= low and np.round(x, 2) <= high))
df.map(lambda x: (np.round(x, 2) >= low and np.round(x, 2) <= high))
.all()
.all()
)
Expand Down
Loading