Skip to content

Commit

Permalink
simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
jpn-- committed Feb 6, 2024
1 parent 66b2063 commit d18ceef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
16 changes: 4 additions & 12 deletions activitysim/core/configuration/top.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from pathlib import Path
from typing import Any, Literal

from activitysim.core.configuration.base import PydanticBase, Union
from pydantic import validator

from activitysim.core.configuration.base import PydanticBase, Union


class InputTable(PydanticBase):
"""
Expand Down Expand Up @@ -120,9 +121,9 @@ class OutputTables(PydanticBase):
h5_store: bool = False
"""Write tables into a single HDF5 store instead of individual CSVs."""

file_type: str = "csv"
file_type: Literal["csv", "parquet", "h5"] = "csv"
"""
Specifies the file type for output tables. Options are limited to 'csv',
Specifies the file type for output tables. Options are limited to 'csv',
'h5' or 'parquet'. Only applied if h5_store is set to False."""

action: str
Expand Down Expand Up @@ -150,15 +151,6 @@ class OutputTables(PydanticBase):
applied to any output tables.
"""

@validator("file_type")
def method_is_valid(cls, method: str) -> str:
"""Validates file_type setting."""

allowed_set = {"csv", "h5", "parquet"}
if method not in allowed_set:
raise ValueError(f"must be in {allowed_set}, got '{method}'")
return method


class MultiprocessStepSlice(PydanticBase, extra="forbid"):
"""
Expand Down
4 changes: 3 additions & 1 deletion activitysim/core/steps/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,5 +413,7 @@ def map_func(x):
# include the index if it has a name or is a MultiIndex
if file_type == "csv":
csv.write_csv(dt, file_path)
else:
elif file_type == "parquet":
parquet.write_table(dt, file_path)
else:
raise ValueError(f"unknown file_type {file_type}")

0 comments on commit d18ceef

Please sign in to comment.