Skip to content

Commit

Permalink
🐛 Fix #65
Browse files Browse the repository at this point in the history
  • Loading branch information
pwwang committed Oct 4, 2021
1 parent aa90055 commit ba8b3e7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion datar/core/grouped.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,15 @@ def _optimizable_func(
"""
if not hasattr(numpy, name):
return None

if kwargs.get("na_rm", False):
# Only optimize when na_rm is True, because
# pandas will ignore NAs anyway
return getattr(numpy, f"nan{name}")
return getattr(numpy, name)

# return getattr(numpy, name)
# refuse to optimize, as NAs get lost by pandas
return None


def _optimizable(
Expand Down
4 changes: 3 additions & 1 deletion tests/test_core_grouped.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ def test_agg():
out = gf._datar_apply(
None,
_mappings=dict(
c=FastEvalFunction(mean, args=(f.b,), kwargs={}, dataarg=False)
c=FastEvalFunction(
mean, args=(f.b,), kwargs={"na_rm": True}, dataarg=False
)
),
_method="agg",
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dplyr_summarise.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def test_errors(caplog):
with pytest.raises(ColumnNotExistingError):
summarise(mtcars, a = mean(f.not_there))

with pytest.raises(KeyError):
with pytest.raises(ColumnNotExistingError):
summarise(group_by(mtcars, f.cyl), a = mean(f.not_there))

# Duplicate column names
Expand Down

0 comments on commit ba8b3e7

Please sign in to comment.