Skip to content

Commit

Permalink
use time_label_dtype only when available
Browse files Browse the repository at this point in the history
  • Loading branch information
jpn-- committed Sep 26, 2023
1 parent b26ad6c commit 8384c3f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions activitysim/core/los.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,14 @@ def skim_time_period_label(
assert 0 == model_time_window_min % period_minutes
total_periods = model_time_window_min / period_minutes

try:
time_label_dtype = self.skim_dicts["taz"].time_label_dtype
except AttributeError:
# if using old SkimDict instead of SkimDataset, this labeling
# shortcut is unavailable.
time_label_dtype = str
as_cat = False

# FIXME - eventually test and use np version always?
if np.isscalar(time_period):
bin = (
Expand All @@ -890,11 +898,11 @@ def skim_time_period_label(
result = self.skim_time_periods["labels"].get(bin, default=default)
else:
result = self.skim_time_periods["labels"][bin]
if broadcast_to is not None and as_cat:
if broadcast_to is not None:
result = pd.Series(
data=result,
index=broadcast_to,
dtype=self.skim_dicts["taz"].time_label_dtype,
dtype=time_label_dtype,
)
else:
result = pd.cut(
Expand All @@ -907,7 +915,7 @@ def skim_time_period_label(
default = self.skim_time_periods["labels"][fillna]
result = result.fillna(default)
if as_cat:
result = result.astype(self.skim_dicts["taz"].time_label_dtype)
result = result.astype(time_label_dtype)
else:
result = result.astype(str)
return result
Expand Down

0 comments on commit 8384c3f

Please sign in to comment.