Skip to content

Commit

Permalink
Remove Datetime validator; replace with IsInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmundt committed Feb 20, 2024
1 parent e667ad3 commit c2472b3
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 31 deletions.
12 changes: 0 additions & 12 deletions pyomo/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import argparse
import builtins
import datetime
import enum
import importlib
import inspect
Expand Down Expand Up @@ -205,16 +204,6 @@ def NonNegativeFloat(val):
return ans


def Datetime(val):
"""Domain validation function to check for datetime.datetime type.
This domain will return the original object, assuming it is of the right type.
"""
if not isinstance(val, datetime.datetime):
raise ValueError(f"Expected datetime object, but received {type(val)}.")
return val


class In(object):
"""In(domain, cast=None)
Domain validation class admitting a Container of possible values
Expand Down Expand Up @@ -794,7 +783,6 @@ def from_enum_or_string(cls, arg):
NegativeFloat
NonPositiveFloat
NonNegativeFloat
Datetime
In
InEnum
IsInstance
Expand Down
17 changes: 0 additions & 17 deletions pyomo/common/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def yaml_load(arg):
ConfigDict,
ConfigValue,
ConfigList,
Datetime,
MarkImmutable,
ImmutableConfigValue,
Bool,
Expand Down Expand Up @@ -937,22 +936,6 @@ def _rule(key, val):
}
)

def test_Datetime(self):
c = ConfigDict()
c.declare('a', ConfigValue(domain=Datetime, default=None))
self.assertEqual(c.get('a').domain_name(), 'Datetime')

self.assertEqual(c.a, None)
c.a = datetime.datetime(2022, 1, 1)
self.assertEqual(c.a, datetime.datetime(2022, 1, 1))

with self.assertRaises(ValueError):
c.a = 5
with self.assertRaises(ValueError):
c.a = 'Hello'
with self.assertRaises(ValueError):
c.a = False


class TestImmutableConfigValue(unittest.TestCase):
def test_immutable_config_value(self):
Expand Down
1 change: 1 addition & 0 deletions pyomo/contrib/solver/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def TextIO_or_Logger(val):
)
return ans


class SolverConfig(ConfigDict):
"""
Base config for all direct solver interfaces
Expand Down
5 changes: 3 additions & 2 deletions pyomo/contrib/solver/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pyomo.common.config import (
ConfigDict,
ConfigValue,
Datetime,
IsInstance,
NonNegativeInt,
In,
NonNegativeFloat,
Expand Down Expand Up @@ -262,7 +262,8 @@ def __init__(
self.timing_info.start_timestamp: datetime = self.timing_info.declare(
'start_timestamp',
ConfigValue(
domain=Datetime, description="UTC timestamp of when run was initiated."
domain=IsInstance(datetime),
description="UTC timestamp of when run was initiated.",
),
)
self.timing_info.wall_time: Optional[float] = self.timing_info.declare(
Expand Down

0 comments on commit c2472b3

Please sign in to comment.