Skip to content

Commit 5141945

Browse files
authored
Merge pull request #796 from camsys/pydantic-2
Pydantic 2
2 parents 6a20954 + 2a72c2f commit 5141945

File tree

17 files changed

+33
-32
lines changed

17 files changed

+33
-32
lines changed

.github/workflows/core_tests.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
mamba env update -n asim-test -f conda-environments/github-actions-tests.yml
5050
mamba install --yes \
5151
"psutil=5.9.5" \
52-
"pydantic=1.10.13" \
52+
"pydantic=2.6.1" \
5353
"pypyr=5.8.0" \
5454
"pytables=3.6.1" \
5555
"pytest-cov" \
@@ -149,7 +149,7 @@ jobs:
149149
mamba env update -n asim-test -f conda-environments/github-actions-tests.yml
150150
mamba install --yes \
151151
"psutil=5.9.5" \
152-
"pydantic=1.10.13" \
152+
"pydantic=2.6.1" \
153153
"pypyr=5.8.0" \
154154
"pytables=3.6.1" \
155155
"pytest-cov" \
@@ -247,7 +247,7 @@ jobs:
247247
mamba env update -n asim-test -f conda-environments/github-actions-tests.yml
248248
mamba install --yes \
249249
"psutil=5.9.5" \
250-
"pydantic=1.10.13" \
250+
"pydantic=2.6.1" \
251251
"pypyr=5.8.0" \
252252
"pytables=3.6.1" \
253253
"pytest-cov" \
@@ -344,7 +344,7 @@ jobs:
344344
mamba env update -n asim-test -f conda-environments/github-actions-tests.yml
345345
mamba install --yes \
346346
"psutil=5.9.5" \
347-
"pydantic=1.10.13" \
347+
"pydantic=2.6.1" \
348348
"pypyr=5.8.0" \
349349
"pytables=3.6.1" \
350350
"pytest-cov" \
@@ -411,7 +411,7 @@ jobs:
411411
mamba env update -n asim-test -f conda-environments/github-actions-tests.yml
412412
mamba install --yes \
413413
"psutil=5.9.5" \
414-
"pydantic=1.10.13" \
414+
"pydantic=2.6.1" \
415415
"pypyr=5.8.0" \
416416
"pytables=3.6.1" \
417417
"pytest-cov" \
@@ -477,7 +477,7 @@ jobs:
477477
mamba env update -n asim-test -f conda-environments/github-actions-tests.yml
478478
mamba install --yes \
479479
"psutil=5.9.5" \
480-
"pydantic=1.10.13" \
480+
"pydantic=2.6.1" \
481481
"pypyr=5.8.0" \
482482
"pytables=3.6.1" \
483483
"pytest-cov" \

activitysim/abm/models/util/logsums.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ def compute_location_choice_logsums(
8484
computed logsums with same index as choosers
8585
"""
8686
if isinstance(model_settings, dict):
87-
model_settings = TourLocationComponentSettings.parse_obj(model_settings)
87+
model_settings = TourLocationComponentSettings.model_validate(model_settings)
8888
if isinstance(logsum_settings, dict):
89-
logsum_settings = TourModeComponentSettings.parse_obj(logsum_settings)
89+
logsum_settings = TourModeComponentSettings.model_validate(logsum_settings)
9090

9191
trace_label = tracing.extend_trace_label(trace_label, "compute_logsums")
9292
logger.debug(f"Running compute_logsums with {choosers.shape[0]:d} choosers")

activitysim/abm/tables/shadow_pricing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ def load_shadow_price_calculator(
12331233
spc : ShadowPriceCalculator
12341234
"""
12351235
if not isinstance(model_settings, TourLocationComponentSettings):
1236-
model_settings = TourLocationComponentSettings.parse_obj(model_settings)
1236+
model_settings = TourLocationComponentSettings.model_validate(model_settings)
12371237

12381238
num_processes = state.get_injectable("num_processes", 1)
12391239

activitysim/abm/test/test_misc/test_load_cached_accessibility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_load_cached_accessibility():
5858
settings = state.settings
5959
input_table_list = settings.input_table_list
6060
input_table_list.append(
61-
configuration.InputTable.parse_obj(
61+
configuration.InputTable.model_validate(
6262
{
6363
"tablename": "accessibility",
6464
"filename": "cached_accessibility.csv",

activitysim/core/configuration/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class PreprocessorSettings(PydanticBase):
118118
The preprocessor will emit rows to a temporary table that match the rows
119119
in this table from the pipeline."""
120120

121-
TABLES: list[str] | None
121+
TABLES: list[str] | None = None
122122
"""Names of the additional tables to be merged for the preprocessor.
123123
124124
Data from these tables will be merged into the primary table, according

activitysim/core/configuration/filesystem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ def read_settings_file(
639639
include_stack: bool = False,
640640
configs_dir_list: tuple[Path] | None = None,
641641
validator_class: type[PydanticBase] | None = None,
642-
) -> dict | PydanticBase:
642+
) -> PydanticBase | dict:
643643
"""
644644
Load settings from one or more yaml files.
645645
@@ -817,7 +817,7 @@ def backfill_settings(settings, backfill):
817817
settings.pop("include_settings", None)
818818

819819
if validator_class is not None:
820-
settings = validator_class.parse_obj(settings)
820+
settings = validator_class.model_validate(settings)
821821

822822
if include_stack:
823823
# if we were called recursively, return an updated list of source_file_paths

activitysim/core/logit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def each_nest(nest_spec: dict | LogitNestSpec, type=None, post_order=False):
574574
raise RuntimeError("Unknown nest type '%s' in call to each_nest" % type)
575575

576576
if isinstance(nest_spec, dict):
577-
nest_spec = LogitNestSpec.parse_obj(nest_spec)
577+
nest_spec = LogitNestSpec.model_validate(nest_spec)
578578

579579
for _node, nest in _each_nest(nest_spec, parent_nest=Nest(), post_order=post_order):
580580
if type is None or (type == nest.type):

activitysim/core/mp_tasks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,6 @@ def setup_injectables_and_logging(injectables, locutor: bool = True) -> workflow
887887
state = workflow.State()
888888
state = state.initialize_filesystem(**injectables)
889889
state.settings = injectables.get("settings", Settings())
890-
# state.settings = Settings.parse_obj(injectables.get("settings_package", {}))
891890

892891
# register abm steps and other abm-specific injectables
893892
# by default, assume we are running activitysim.abm

activitysim/core/simulate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def replace_coefficients(nest: LogitNestSpec):
467467
coefficients = coefficients["value"].to_dict()
468468

469469
if not isinstance(nest_spec, LogitNestSpec):
470-
nest_spec = LogitNestSpec.parse_obj(nest_spec)
470+
nest_spec = LogitNestSpec.model_validate(nest_spec)
471471

472472
replace_coefficients(nest_spec)
473473

activitysim/core/test/test_input.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def test_csv_reader(seed_households, state):
6969
"""
7070

7171
settings = yaml.load(settings_yaml, Loader=yaml.SafeLoader)
72-
settings = configuration.Settings.parse_obj(settings)
72+
settings = configuration.Settings.model_validate(settings)
7373
state.settings = settings
7474

7575
hh_file = state.filesystem.get_data_dir()[0].joinpath("households.csv")
@@ -94,7 +94,7 @@ def test_hdf_reader1(seed_households, state):
9494
"""
9595

9696
settings = yaml.load(settings_yaml, Loader=yaml.SafeLoader)
97-
settings = configuration.Settings.parse_obj(settings)
97+
settings = configuration.Settings.model_validate(settings)
9898
state.settings = settings
9999

100100
hh_file = state.filesystem.get_data_dir()[0].joinpath("households.h5")
@@ -120,7 +120,7 @@ def test_hdf_reader2(seed_households, state):
120120
"""
121121

122122
settings = yaml.load(settings_yaml, Loader=yaml.SafeLoader)
123-
settings = configuration.Settings.parse_obj(settings)
123+
settings = configuration.Settings.model_validate(settings)
124124
state.settings = settings
125125

126126
hh_file = state.filesystem.get_data_dir()[0].joinpath("households.h5")
@@ -145,7 +145,7 @@ def test_hdf_reader3(seed_households, state):
145145
"""
146146

147147
settings = yaml.load(settings_yaml, Loader=yaml.SafeLoader)
148-
settings = configuration.Settings.parse_obj(settings)
148+
settings = configuration.Settings.model_validate(settings)
149149
state.settings = settings
150150

151151
hh_file = state.filesystem.get_data_dir()[0].joinpath("input_data.h5")
@@ -169,7 +169,7 @@ def test_missing_filename(seed_households, state):
169169
"""
170170

171171
settings = yaml.load(settings_yaml, Loader=yaml.SafeLoader)
172-
settings = configuration.Settings.parse_obj(settings)
172+
settings = configuration.Settings.model_validate(settings)
173173
state.settings = settings
174174

175175
with pytest.raises(AssertionError) as excinfo:
@@ -191,7 +191,7 @@ def test_create_input_store(seed_households, state):
191191
"""
192192

193193
settings = yaml.load(settings_yaml, Loader=yaml.SafeLoader)
194-
settings = configuration.Settings.parse_obj(settings)
194+
settings = configuration.Settings.model_validate(settings)
195195
state.settings = settings
196196

197197
hh_file = state.filesystem.get_data_dir()[0].joinpath("households.csv")

0 commit comments

Comments
 (0)