@@ -64,8 +64,8 @@ def __init__(self, file_path):
6464 self .data_cols = column_names [2 :]
6565
6666 od_table = parquet_file .read (columns = [self .orig_col , self .dest_col ])
67- origins = od_table . column ( self .orig_col ) .to_numpy (zero_copy_only = False )
68- destinations = od_table . column ( self .dest_col ) .to_numpy (zero_copy_only = False )
67+ origins = od_table [ self .orig_col ] .to_numpy (zero_copy_only = False )
68+ destinations = od_table [ self .dest_col ] .to_numpy (zero_copy_only = False )
6969
7070 zone_ids = np .unique (np .concatenate ([origins , destinations ]))
7171 self .zone_ids = zone_ids
@@ -76,13 +76,8 @@ def __init__(self, file_path):
7676 n_rows = len (origins )
7777 self .is_dense = n_rows == self .n_zones * self .n_zones
7878
79- zone_index = {z : i for i , z in enumerate (zone_ids )}
80- orig_idx = np .fromiter (
81- (zone_index [o ] for o in origins ), dtype = np .int64 , count = n_rows
82- )
83- dest_idx = np .fromiter (
84- (zone_index [d ] for d in destinations ), dtype = np .int64 , count = n_rows
85- )
79+ orig_idx = np .searchsorted (zone_ids , origins )
80+ dest_idx = np .searchsorted (zone_ids , destinations )
8681 self ._orig_idx = orig_idx
8782 self ._dest_idx = dest_idx
8883
@@ -134,7 +129,7 @@ def read_matrix(self, column_name, dtype=None):
134129 np.ndarray, shape (n_zones, n_zones)
135130 """
136131 table = pq .read_table (self .file_path , columns = [column_name ])
137- values = table . column ( column_name ) .to_numpy (zero_copy_only = False )
132+ values = table [ column_name ] .to_numpy (zero_copy_only = False )
138133 if dtype is not None :
139134 values = values .astype (dtype , copy = False )
140135
0 commit comments