Skip to content

Commit cff046e

Browse files
committed
Changed reading of test data.
1 parent f87522e commit cff046e

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

ruspy/test/test_replication.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import yaml
1313
import numpy as np
1414
import pandas as pd
15+
import os
1516
from numpy.testing import assert_array_almost_equal, assert_array_equal, assert_allclose
1617
from ruspy.estimation.estimation import estimate
1718
from ruspy.ruspy_config import TEST_RESOURCES_DIR
@@ -20,15 +21,12 @@
2021

2122
with open(TEST_RESOURCES_DIR + "replication_test/init_replication_test.yml") as y:
2223
init_dict = yaml.safe_load(y)
23-
group_folder = "replication_test/group_4/"
24-
bus_id = np.loadtxt(TEST_RESOURCES_DIR + group_folder + "Bus_ID.txt", dtype=int)
25-
state = np.loadtxt(TEST_RESOURCES_DIR + group_folder + "state.txt", dtype=int)
26-
decision = np.loadtxt(TEST_RESOURCES_DIR + group_folder + "decision.txt", dtype=int)
27-
period = np.loadtxt(TEST_RESOURCES_DIR + group_folder + "period.txt", dtype=int)
28-
data = pd.DataFrame(
29-
{"Bus_ID": bus_id, "state": state, "decision": decision, "period": period}
30-
)
31-
result_trans, result_fixp = estimate(init_dict["replication"], data, repl_4=True)
24+
group_folder = TEST_RESOURCES_DIR + "replication_test/group_4/"
25+
data = {}
26+
for file in os.listdir(group_folder):
27+
data[os.fsdecode(file)[:-4]] = np.loadtxt(group_folder + file, dtype=int)
28+
df = pd.DataFrame(data)
29+
result_trans, result_fixp = estimate(init_dict["replication"], df, repl_4=True)
3230

3331

3432
@pytest.fixture
@@ -75,10 +73,10 @@ def test_cost_ll(inputs, outputs):
7573

7674

7775
def test_transition_count(outputs):
78-
num_bus = len(data["Bus_ID"].unique())
79-
num_periods = int(data.shape[0] / num_bus)
80-
states = data["state"].values.reshape(num_bus, num_periods)
81-
decisions = data["decision"].values.reshape(num_bus, num_periods)
76+
num_bus = len(df["Bus_ID"].unique())
77+
num_periods = int(df.shape[0] / num_bus)
78+
states = df["state"].values.reshape(num_bus, num_periods)
79+
decisions = df["decision"].values.reshape(num_bus, num_periods)
8280
space_state = states.max() + 1
8381
state_count = np.zeros(shape=(space_state, space_state), dtype=int)
8482
increases = np.zeros(shape=(num_bus, num_periods - 1), dtype=int)

0 commit comments

Comments
 (0)