Ticket #8934 (assigned)

Opened 7 years ago

Last modified 5 years ago

Inconsistent usage of IntArrayBoundedValidator in Python

Reported by: Martyn Gigg Owned by:
Priority: major Milestone: Backlog
Component: Python Keywords:
Cc: Blocked By:
Blocking: Tester:

Description

Dear Mantid team, I just stumbled accross some inconvenience as I wanted to declare an array property where the individual values are supposed to have a minimum, but not a maximum value.

For single numbers it is very convenient:

self.declareProperty('SingleNonNegativeInt', 0,

direction = Direction.Input, doc = "a non-negative integer", validator=IntBoundedValidator(lower=0.))

But for an array it does not work like this:

theProp = IntArrayProperty(name='PositiveNumbers',

validator = IntArrayBoundedValidator(lowerBound=1), direction = Direction.Input)

self.declareProperty(theProp, doc = "Positive integers")

# (Nasty anyway that here it is 'lowerBound' # whereas for non-arrays it is 'lower'...)

This is because 'IntArrayBoundedValidator' does not have default arguments nor understands 'None'. This is the workaround:

onlyLowerBound = IntArrayBoundedValidator(lowerBound=1, upperBound=1) onlyLowerBound.clearUpper() theProp = IntArrayProperty(name='PositiveNumbers',

validator = onlyLowerBound, direction = Direction.Input)

self.declareProperty(theProp, doc = "Positive integers")

Would be nice if setting bounds on single values or arrays would behave similarly (and in an easy way)...

Change History

comment:1 Changed 7 years ago by Nick Draper

  • Status changed from new to assigned

bulk move to assigned at the into of the triage step

comment:2 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 9777

Note: See TracTickets for help on using tickets.