Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple classes not being presented in the returned d #438

Merged
merged 7 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions aequilibrae/matrix/aequilibrae_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ def create_empty(
# raise ValueError('Data types need to be Python or Numpy data types')

for field in self.fields:
if not type(field) is str:
raise TypeError(field + " is not a string. You cannot use it as a field name")
if not field.isidentifier():
raise Exception(field + " is a not a valid identifier name. You cannot use it as a field name")
if field in object.__dict__:
raise Exception(field + " is a reserved name. You cannot use it as a field name")

Expand Down
10 changes: 3 additions & 7 deletions aequilibrae/paths/traffic_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ def select_link_flows(self) -> Dict[str, pd.DataFrame]:
"""
Returns a dataframe of the select link flows for each class
"""
sl_flows = None # stores the df for each class
class_flows = [] # stores the df for each class
for cls in self.classes:
# Save OD_matrices
if cls._selected_links is None:
Expand All @@ -699,12 +699,8 @@ def select_link_flows(self) -> Dict[str, pd.DataFrame]:
cls_cols = {x: cls.__id__ + "_" + x if (x != "index") else "link_id" for x in df.columns}
df.rename(columns=cls_cols, inplace=True)
df.set_index("link_id", inplace=True)
if sl_flows is None:
sl_flows = df
else:
sl_flows.join(df)
# sl_flows = pd.concat(class_flows, axis=1)
return sl_flows
class_flows.append(df)
return pd.concat(class_flows, axis=1)

def save_select_link_flows(self, table_name: str, project=None) -> None:
"""
Expand Down
9 changes: 5 additions & 4 deletions tests/aequilibrae/paths/test_select_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def setUp(self) -> None:
self.assignment.set_time_field("free_flow_time")
self.assignment.max_iter = 1
self.assignment.set_algorithm("msa")
self.assignment.set_cores(1)

def tearDown(self) -> None:
self.matrix.close()
Expand All @@ -50,7 +51,7 @@ def test_multiple_link_sets(self):
Uses two examples: 2 links in one select link, and a single Selected Link
Checks both the OD Matrix and Link Loading
"""
self.assignclass.set_select_links({"9 or 6": [(9, 1), (6, 1)], "just 3": [(3, 1)], "5 for fun": [(5, 1)]})
self.assignclass.set_select_links({"sl 9 or 6": [(9, 1), (6, 1)], "just 3": [(3, 1)], "sl 5 for fun": [(5, 1)]})
self.assignment.execute()
for key in self.assignclass._selected_links.keys():
od_mask, link_loading = create_od_mask(
Expand All @@ -73,7 +74,7 @@ def test_equals_demand_one_origin(self):
Tests to make sure the OD matrix works when all links surrounding one origin are selected
Confirms the Link Loading is done correctly in this case
"""
self.assignclass.set_select_links({"1, 4, 3, and 2": [(1, 1), (4, 1), (3, 1), (2, 1)]})
self.assignclass.set_select_links({"sl 1, 4, 3, and 2": [(1, 1), (4, 1), (3, 1), (2, 1)]})

self.assignment.execute()

Expand Down Expand Up @@ -102,7 +103,7 @@ def test_single_demand(self):
self.matrix.matrix_view = custom_demand
self.assignclass.matrix = self.matrix

self.assignclass.set_select_links({"39, 66, or 73": [(39, 1), (66, 1), (73, 1)]})
self.assignclass.set_select_links({"sl 39, 66, or 73": [(39, 1), (66, 1), (73, 1)]})

self.assignment.execute()
for key in self.assignclass._selected_links.keys():
Expand All @@ -127,7 +128,7 @@ def test_select_link_network_loading(self):
self.assignment.execute()
non_sl_loads = self.assignclass.results.get_load_results()
self.setUp()
self.assignclass.set_select_links({"39, 66, or 73": [(39, 1), (66, 1), (73, 1)]})
self.assignclass.set_select_links({"sl 39, 66, or 73": [(39, 1), (66, 1), (73, 1)]})
self.assignment.execute()
sl_loads = self.assignclass.results.get_load_results()
np.testing.assert_allclose(non_sl_loads.matrix_tot, sl_loads.matrix_tot)
Expand Down
4 changes: 3 additions & 1 deletion tests/aequilibrae/project/test_place_getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def test_placegetter(self):

if random() < thresh:
place, report = placegetter("Vatican City")
if place is None:
self.skipTest("Skipping... either Vatican City doesn't exist anymore or there was a network failure")
place = [round(x, 1) for x in place]
if place != [12.4, 41.9, 12.5, 41.9]:
self.fail("Returned the wrong boundingbox for Vatican City")
Expand All @@ -20,4 +22,4 @@ def test_placegetter(self):
if place is not None:
self.fail("Returned a bounding box for a place that does not exist")
else:
print("Skipped check to not load OSM servers")
self.skipTest("Skipped check to not load OSM servers")
2 changes: 1 addition & 1 deletion tests/aequilibrae/transit/functions/test_get_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def test_get_table(transit_conn):
tables = get_table("routes", transit_conn)

assert type(tables) == pd.DataFrame
assert type(tables) is pd.DataFrame


def test_list_tables_in_db(transit_conn):
Expand Down
2 changes: 1 addition & 1 deletion tests/aequilibrae/transit/test_lib_gtfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_set_capacities(system_builder):

def test_dates_available(system_builder):
dates = system_builder.dates_available()
assert type(dates) == list
assert type(dates) is list


def test_set_allow_map_match(system_builder):
Expand Down