Skip to content

Commit 8c00aac

Browse files
authored
Address review comments: searchsorted, table[col] indexing, caching, docstring
1 parent 288c238 commit 8c00aac

3 files changed

Lines changed: 7 additions & 11 deletions

File tree

activitysim/core/configuration/network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class TAZ_Settings(PydanticBase):
127127
is not available.
128128
129129
As an alternative to OMX, skim files can instead be provided in Parquet
130-
format (using a ``.parquet`` file extension). The input format is
130+
format (using a ``.parquet`` or ``.pq`` file extension). The input format is
131131
auto-detected from the file extension, so no other settings need to
132132
change to use Parquet input. Parquet skim files should have an origin
133133
column and a destination column (the first two columns in the file),

activitysim/core/skim_dict_factory.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ def _read_skims_from_omx(self, skim_info, skim_data):
387387
parquet_skim_file = skim_info.parquet_files.get(omx_file_path)
388388
if parquet_skim_file is None:
389389
parquet_skim_file = ParquetSkimFile(omx_file_path)
390+
skim_info.parquet_files[omx_file_path] = parquet_skim_file
390391
for skim_key, omx_key in omx_keys.items():
391392
if omx_manifest[omx_key] == omx_file_path:
392393
offset = skim_info.block_offsets[skim_key]

activitysim/core/skim_parquet.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)