Skip to content

Commit

Permalink
added comment and refactored test vars
Browse files Browse the repository at this point in the history
  • Loading branch information
sablanchard committed Mar 27, 2017
1 parent 1d138a2 commit b3c9d1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pandana/tests/test_utils.py
Expand Up @@ -5,7 +5,7 @@


@pytest.fixture
def dataframe():
def node_df():
data = {'node_id': [44, 55, 33, 22, 11],
'x': [-122, -123, -124, -125, -126],
'y': [37, 38, 39, 40, 41]}
Expand All @@ -16,7 +16,7 @@ def dataframe():


@pytest.fixture
def series():
def result_series():
data = {'value': [10, 20, 30, 40, 50]}
index = [11, 22, 33, 44, 55]
df = pd.DataFrame(data, index)
Expand All @@ -25,10 +25,11 @@ def series():
return s


def test_reindex(dataframe, series):
def test_reindex(node_df, result_series):

results = pd.DataFrame({'value': reindex(series, dataframe.node_id)})
reindexed_results = pd.DataFrame({'value': reindex(result_series,
node_df.node_id)})

assert len(results) == 5
assert results['value'][1] == 40
assert results['value'][5] == 10
assert len(reindexed_results) == 5
assert reindexed_results['value'][1] == 40
assert reindexed_results['value'][5] == 10
2 changes: 2 additions & 0 deletions pandana/utils.py
Expand Up @@ -17,6 +17,8 @@ def reindex(series1, series2):
df.right : pandas.DataFrame
"""

# this function is identical to the reindex function found in UrbanSim in
# urbansim/utils/misc.py
df = pd.merge(pd.DataFrame({"left": series2}),
pd.DataFrame({"right": series1}),
left_on="left",
Expand Down

0 comments on commit b3c9d1c

Please sign in to comment.