Skip to content

Commit

Permalink
Adding tests for hedonic.apply_filter_query.
Browse files Browse the repository at this point in the history
  • Loading branch information
jiffyclub committed Apr 9, 2014
1 parent cebe3ce commit 67e5d6d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Empty file.
43 changes: 43 additions & 0 deletions urbansim/models/tests/test_hedonic.py
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)



0 comments on commit 67e5d6d

Please sign in to comment.