From aaecd3c3449a23599503a5f22c8fb4b29a250ea7 Mon Sep 17 00:00:00 2001 From: Yue Shuai <48269801+yueshuaing@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:53:55 -0700 Subject: [PATCH] code changes based on new network wrangler --- methods_add_cards.py | 31 ++++++++++++++++--------------- methods_io.py | 4 ++-- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/methods_add_cards.py b/methods_add_cards.py index 7e21861..ed3cb69 100644 --- a/methods_add_cards.py +++ b/methods_add_cards.py @@ -2,7 +2,8 @@ from numpy import True_ import pandas as pd from typing import Tuple -from network_wrangler import ProjectCard +from projectcard import ProjectCard +from projectcard import write_card def add_cards_to_registry( @@ -30,8 +31,8 @@ def add_cards_to_registry( for card, filename in card_file_list: if card.project not in input_df["project_added"].values: for change_index, change_dict in enumerate(card.changes): - if change_dict.get("category", "Missing") == "Add New Roadway": - if "nodes" in change_dict: + if "roadway_addition" in change_dict: + if "nodes" in change_dict["roadway_addition"]: node_df, node_update, card = _update_registry( "nodes", out_df, @@ -52,10 +53,10 @@ def add_cards_to_registry( ) if node_df is not None: - out_df = out_df.append(node_df, ignore_index=True) + out_df = pd.concat([out_df, node_df], ignore_index=True) out_df = ( - out_df.append(link_df, ignore_index=True) + pd.concat([out_df, link_df], ignore_index=True) .drop_duplicates() .reset_index(drop=True) ) @@ -66,7 +67,7 @@ def add_cards_to_registry( card.__dict__.pop("file") if "valid" in card.__dict__: card.__dict__.pop("valid") - card.write(filename=filename) + write_card(filename=filename) return out_df @@ -238,7 +239,7 @@ def _update_registry( subject_df = input_df[input_df["type"] == subject_word] - for subject_index, subject in enumerate(card.changes[change_index][nodes_or_links]): + for subject_index, subject in enumerate(card.changes[change_index]["roadway_addition"][nodes_or_links]): new_id = subject[subject_id_word] _is_id_in_allowable_range(subject_word, card.project, new_id, range_in_use) @@ -251,7 +252,7 @@ def _update_registry( "project_added": [card.project], } ) - subject_df = subject_df.append(updates_df) + subject_df = pd.concat([subject_df, updates_df]) else: number = _find_available_id( subject_word, @@ -260,15 +261,15 @@ def _update_registry( range_in_use, subject_df, ) - card.changes[change_index][nodes_or_links][subject_index][ + card.changes[change_index]["roadway_addition"][nodes_or_links][subject_index][ subject_id_word ] = number if nodes_or_links == "nodes": - for i in range(0, len(card.changes[change_index]["links"])): - if card.changes[change_index]["links"][i]["A"] == new_id: - card.changes[change_index]["links"][i]["A"] = number - if card.changes[change_index]["links"][i]["B"] == new_id: - card.changes[change_index]["links"][i]["B"] = number + for i in range(0, len(card.changes[change_index]["roadway_addition"]["links"])): + if card.changes[change_index]["roadway_addition"]["links"][i]["A"] == new_id: + card.changes[change_index]["roadway_addition"]["links"][i]["A"] = number + if card.changes[change_index]["roadway_addition"]["links"][i]["B"] == new_id: + card.changes[change_index]["roadway_addition"]["links"][i]["B"] = number updates_df = pd.DataFrame( { "type": subject_word, @@ -276,7 +277,7 @@ def _update_registry( "project_added": [card.project], } ) - subject_df = subject_df.append(updates_df) + subject_df = pd.concat([subject_df, updates_df]) write_updated_card = True return subject_df, write_updated_card, card diff --git a/methods_io.py b/methods_io.py index b29a816..2a17dc2 100644 --- a/methods_io.py +++ b/methods_io.py @@ -1,5 +1,5 @@ import os -from network_wrangler import ProjectCard +from projectcard import read_card CARD_DIR = os.path.join(".", "projects") @@ -22,7 +22,7 @@ def read_project_cards(card_dir: str = CARD_DIR) -> list: name, extension = os.path.splitext(filename) if extension in [".yml", ".yaml"]: card_file = os.path.join(dirpath, filename) - card = ProjectCard.read(card_file, validate=False) + card = read_card(card_file, validate=False) card_file_list.append((card, card_file)) return card_file_list