-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding tests for hedonic.apply_filter_query.
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pandas as pd | ||
import pytest | ||
from pandas.util import testing as pdt | ||
|
||
from .. import hedonic | ||
|
||
|
||
@pytest.fixture | ||
def test_df(): | ||
return pd.DataFrame( | ||
{'col1': range(5), | ||
'col2': range(5, 10)}, | ||
index=['a', 'b', 'c', 'd', 'e']) | ||
|
||
|
||
def test_apply_filter_query(test_df): | ||
filters = ['col1 < 3', 'col2 > 6'] | ||
filtered = hedonic.apply_filter_query(test_df, filters) | ||
expected = pd.DataFrame( | ||
{'col1': [2], 'col2': [7]}, | ||
index=['c']) | ||
pdt.assert_frame_equal(filtered, expected) | ||
|
||
|
||
def test_apply_filter_query_empty(test_df): | ||
filters = ['col1 < 1', 'col2 > 8'] | ||
filtered = hedonic.apply_filter_query(test_df, filters) | ||
expected = pd.DataFrame( | ||
{'col1': [], 'col2': []}, | ||
index=[]) | ||
pdt.assert_frame_equal(filtered, expected) | ||
|
||
|
||
def test_apply_filter_query_or(test_df): | ||
filters = ['col1 < 1 or col2 > 8'] | ||
filtered = hedonic.apply_filter_query(test_df, filters) | ||
expected = pd.DataFrame( | ||
{'col1': [0, 4], 'col2': [5, 9]}, | ||
index=['a', 'e']) | ||
pdt.assert_frame_equal(filtered, expected) | ||
|
||
|
||
|