@@ -4181,6 +4181,19 @@ def test_indexed_set(self):
4181
4181
self .assertIs (type (m .I [3 ]), InsertionOrderSetData )
4182
4182
self .assertEqual (m .I .data (), {1 : (4 , 2 , 5 ), 2 : (4 , 2 , 5 ), 3 : (4 , 2 , 5 )})
4183
4183
4184
+ # Explicit (constant dict) construction
4185
+ m = ConcreteModel ()
4186
+ m .I = Set ([1 , 2 ], initialize = {1 : (4 , 2 , 5 ), 2 : (7 , 6 )})
4187
+ self .assertEqual (len (m .I ), 2 )
4188
+ self .assertEqual (list (m .I [1 ]), [4 , 2 , 5 ])
4189
+ self .assertEqual (list (m .I [2 ]), [7 , 6 ])
4190
+ self .assertIsNot (m .I [1 ], m .I [2 ])
4191
+ self .assertTrue (m .I [1 ].isordered ())
4192
+ self .assertTrue (m .I [2 ].isordered ())
4193
+ self .assertIs (type (m .I [1 ]), InsertionOrderSetData )
4194
+ self .assertIs (type (m .I [2 ]), InsertionOrderSetData )
4195
+ self .assertEqual (m .I .data (), {1 : (4 , 2 , 5 ), 2 : (7 , 6 )})
4196
+
4184
4197
# Explicit (constant) construction
4185
4198
m = ConcreteModel ()
4186
4199
m .I = Set ([1 , 2 , 3 ], initialize = (4 , 2 , 5 ), ordered = Set .SortedOrder )
@@ -4255,7 +4268,7 @@ def test_indexing(self):
4255
4268
def test_add_filter_validate (self ):
4256
4269
m = ConcreteModel ()
4257
4270
m .I = Set (domain = Integers )
4258
- self .assertIs (m .I .filter , None )
4271
+ self .assertIs (m .I ._filter , None )
4259
4272
with self .assertRaisesRegex (
4260
4273
ValueError ,
4261
4274
r"Cannot add value 1.5 to Set I.\n"
@@ -4302,7 +4315,7 @@ def _l_tri(model, i, j):
4302
4315
return i >= j
4303
4316
4304
4317
m .K = Set (initialize = RangeSet (3 ) * RangeSet (3 ), filter = _l_tri )
4305
- self .assertIsInstance (m .K .filter , ParameterizedScalarCallInitializer )
4318
+ self .assertIsInstance (m .K ._filter , ParameterizedScalarCallInitializer )
4306
4319
self .assertEqual (list (m .K ), [(1 , 1 ), (2 , 1 ), (2 , 2 ), (3 , 1 ), (3 , 2 ), (3 , 3 )])
4307
4320
4308
4321
output = StringIO ()
@@ -4334,6 +4347,18 @@ def _lt_3(model, i):
4334
4347
self .assertEqual (output .getvalue (), "" )
4335
4348
self .assertEqual (list (m .L [2 ]), [1 , 2 , 0 ])
4336
4349
4350
+ # This tests that the deprecation path works correctly in the
4351
+ # case that the callback doesn't raise an error or ever return
4352
+ # False
4353
+
4354
+ def _l_off_diag (model , i , j ):
4355
+ self .assertIs (model , m )
4356
+ return i != j
4357
+
4358
+ m .M = Set (initialize = RangeSet (3 ) * RangeSet (3 ), filter = _l_off_diag )
4359
+ self .assertIsInstance (m .M ._filter , ParameterizedScalarCallInitializer )
4360
+ self .assertEqual (list (m .M ), [(1 , 2 ), (1 , 3 ), (2 , 1 ), (2 , 3 ), (3 , 1 ), (3 , 2 )])
4361
+
4337
4362
m = ConcreteModel ()
4338
4363
4339
4364
def _validate (model , val ):
@@ -4374,12 +4399,15 @@ def _validate(model, i, j):
4374
4399
m .I2 = Set (validate = _validate )
4375
4400
with LoggingIntercept (module = 'pyomo.core' ) as output :
4376
4401
self .assertTrue (m .I2 .add ((0 , 1 )))
4377
- self .assertRegex (
4378
- output .getvalue ().replace ('\n ' , ' ' ),
4379
- r"DEPRECATED: OrderedScalarSet I2: 'validate=' callback "
4380
- r"signature matched \(block, \*value\). Please update the "
4381
- r"callback to match the signature \(block, value\)" ,
4382
- )
4402
+ # Note that we are not emitting a deprecation warning (yet)
4403
+ # for scalar sets
4404
+ # self.assertEqual(output.getvalue(), "")
4405
+ # output.getvalue().replace('\n', ' '),
4406
+ # r"DEPRECATED: OrderedScalarSet I2: 'validate=' callback "
4407
+ # r"signature matched \(block, \*value\). Please update the "
4408
+ # r"callback to match the signature \(block, value\)",
4409
+ # )
4410
+ self .assertEqual (output .getvalue (), "" )
4383
4411
with LoggingIntercept (module = 'pyomo.core' ) as output :
4384
4412
with self .assertRaisesRegex (
4385
4413
ValueError ,
0 commit comments