Skip to content

Commit dec3ea5

Browse files
committed
Convert timeslice id to int, fix failing test
1 parent 538c510 commit dec3ea5

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/muse/new_input/readers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def read_inputs(data_dir):
4141

4242
def read_timeslices_csv(buffer_, con):
4343
sql = """CREATE TABLE timeslices (
44-
id VARCHAR PRIMARY KEY,
44+
id BIGINT PRIMARY KEY,
4545
season VARCHAR,
4646
day VARCHAR,
4747
time_of_day VARCHAR,
@@ -133,7 +133,7 @@ def read_demand_slicing_csv(buffer_, con):
133133
commodity VARCHAR REFERENCES commodities(id),
134134
region VARCHAR REFERENCES regions(id),
135135
year BIGINT,
136-
timeslice VARCHAR REFERENCES timeslices(id),
136+
timeslice BIGINT REFERENCES timeslices(id),
137137
fraction DOUBLE CHECK (fraction >= 0 AND fraction <= 1),
138138
PRIMARY KEY (commodity, region, year, timeslice),
139139
FOREIGN KEY (commodity, region, year) REFERENCES demand(commodity, region, year)
@@ -201,7 +201,7 @@ def calculate_demand(
201201
all_commodities = commodities["id"].astype(np.dtype("str"))
202202
all_regions = regions["id"].astype(np.dtype("str"))
203203
all_years = df_demand.index.get_level_values("year").unique()
204-
all_timeslices = timeslices["id"].astype(np.dtype("str"))
204+
all_timeslices = timeslices["id"].astype(np.dtype("int"))
205205

206206
# CHECK: all years are specified for each commodity/region combination
207207
check_all_values_specified(df_demand, ["commodity", "region"], "year", all_years)

tests/test_new_readers.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ def populate_demand(default_new_input, con, populate_regions, populate_commoditi
5757

5858
@fixture
5959
def populate_demand_slicing(
60-
default_new_input, con, populate_regions, populate_commodities, populate_demand
60+
default_new_input,
61+
con,
62+
populate_regions,
63+
populate_commodities,
64+
populate_demand,
65+
populate_timeslices,
6166
):
6267
from muse.new_input.readers import read_demand_slicing_csv
6368

@@ -84,7 +89,7 @@ def populate_timeslices(default_new_input, con):
8489
def test_read_timeslices_csv(populate_timeslices):
8590
data = populate_timeslices
8691
assert len(data["id"]) == 6
87-
assert next(iter(data["id"])) == "1"
92+
assert next(iter(data["id"])) == 1
8893
assert next(iter(data["season"])) == "all"
8994
assert next(iter(data["day"])) == "all"
9095
assert next(iter(data["time_of_day"])) == "night"
@@ -202,7 +207,7 @@ def test_calculate_demand(
202207

203208
assert set(data.dims) == {"year", "commodity", "region", "timeslice"}
204209
assert list(data.coords["region"].values) == ["R1"]
205-
assert list(data.coords["timeslice"].values) == ["1", "2", "3", "4", "5", "6"]
210+
assert set(data.coords["timeslice"].values) == set(range(1, 7))
206211
assert list(data.coords["year"].values) == [2020, 2050]
207212
assert set(data.coords["commodity"].values) == {
208213
"electricity",
@@ -212,7 +217,7 @@ def test_calculate_demand(
212217
"CO2f",
213218
}
214219

215-
assert data.sel(year=2020, commodity="heat", region="R1", timeslice="1") == 1
220+
assert data.sel(year=2020, commodity="heat", region="R1", timeslice=1) == 1
216221

217222

218223
@mark.xfail

0 commit comments

Comments
 (0)