argsloader.units.numeric¶
IntervalUnit¶
-
class
argsloader.units.numeric.
IntervalUnit
(intervals)[source]¶ - Overview:
A unit for determining if a number falls within the intervals.
-
L
(left) → argsloader.units.numeric.IntervalUnit¶ Left-bounded interval with positive infinite right bound, like
[left, +inf]
.- Parameters
left – Left bound, which is included.
- Returns
New interval unit object which contains the new interval and all old intervals.
-
LR
(left, right) → argsloader.units.numeric.IntervalUnit¶ Both-side-bounded interval, like
[left, right]
.- Parameters
left – Left bound, which is included.
right – Right bound, which is included.
- Returns
New interval unit object which contains the new interval and all old intervals.
-
Lr
(left, right) → argsloader.units.numeric.IntervalUnit¶ Left-bounded right-inbounded interval, like
[left, right)
.- Parameters
left – Left bound, which is included.
right – Right bound, which is not included.
- Returns
New interval unit object which contains the new interval and all old intervals.
-
R
(right) → argsloader.units.numeric.IntervalUnit¶ Right-bounded interval with negative infinite left bound, like
[-inf, right)
.- Parameters
right – Right bound, which is included.
- Returns
New interval unit object which contains the new interval and all old intervals.
-
__init__
(intervals)[source]¶ Constructor of class
IntervalUnit
.- Parameters
intervals – Interval tuples.
-
l
(left) → argsloader.units.numeric.IntervalUnit¶ Left-inbounded interval with positive infinite right bound, like
(left, +inf]
.- Parameters
left – Left bound, which is not included.
- Returns
New interval unit object which contains the new interval and all old intervals.
-
lR
(left, right) → argsloader.units.numeric.IntervalUnit¶ Left-inbounded right-bounded interval, like
(left, right]
.- Parameters
left – Left bound, which is not included.
right – Right bound, which is included.
- Returns
New interval unit object which contains the new interval and all old intervals.
-
lr
(left, right) → argsloader.units.numeric.IntervalUnit¶ Both-side-inbounded interval, like
(left, right)
.- Parameters
left – Left bound, which is not included.
right – Right bound, which is not included.
- Returns
New interval unit object which contains the new interval and all old intervals.
-
r
(right) → argsloader.units.numeric.IntervalUnit¶ Right-inbounded interval with negative infinite left bound, like
[-inf, right)
.- Parameters
right – Right bound, which is not included.
- Returns
New interval unit object which contains the new interval and all old intervals.
interval¶
-
argsloader.units.numeric.
interval
¶ - Overview:
Interval builder.
For further information, see
IntervalUnit
.- Intervals:
l(x)
: Left-inbounded interval with positive infinite right bound, like(x, +inf]
. SeeIntervalUnit.l()
.L(x)
: Left-bounded interval with positive infinite right bound, like[x, +inf]
. SeeIntervalUnit.L()
.r(x)
: Right-inbounded interval with negative infinite left bound, like[-inf, x)
. SeeIntervalUnit.r()
.R(x)
: Right-bounded interval with negative infinite left bound, like[-inf, x]
. SeeIntervalUnit.R()
.lr(x, y)
: Both-side-inbounded interval, like(x, y)
. SeeIntervalUnit.lr()
.Lr(x, y)
: Left-bounded right-inbounded interval, like[x, y)
. SeeIntervalUnit.Lr()
.lR(x, y)
: Left-inbounded right-bounded interval, like(x, y]
. SeeIntervalUnit.lR()
.LR(x, y)
: Both-side-bounded interval, like[x, y]
. SeeIntervalUnit.LR()
.
- Examples::
>>> from argsloader.units import interval >>> u = interval.lR(3, 10) # (3, 10] >>> u(4.5) 4.5 >>> u(12) ValueParseError: Value not in interval - (3, 10] expected but 12 found. >>> u(3) ValueParseError: Value not in interval - (3, 10] expected but 3 found. >>> ... u = interval.lR(3, 10).L(12) # (3, 10] | [12, +inf] >>> u(4.5) 4.5 >>> u(12) 12 >>> u(3) ValueParseError: Value not in interval - (3, 10] | [12, +inf] expected but 3 found.
positive¶
-
argsloader.units.numeric.
positive
()[source]¶ - Overview:
Check if the value is positive.
Similar to
interval.l(0)
. Seeinterval()
.- Examples::
Simple usage
>>> from argsloader.units import positive >>> u = positive() >>> u(1) 1 >>> u(0.25) 0.25 >>> u(0) ValueParseError: Value not in interval - (0, +inf] expected but 0 found.
Positive integer
>>> u = positive.int() >>> u(1) 1 >>> u(0.25) TypeParseError: Value type not match - int expected but float found. >>> u(0) ValueParseError: Value not in interval - (0, +inf] expected but 0 found.
negative¶
-
argsloader.units.numeric.
negative
()[source]¶ - Overview:
Check if the value is negative.
Similar to
interval.r(0)
. Seeinterval()
.- Examples::
Simple usage
>>> from argsloader.units import negative >>> u = negative() >>> u(-1) -1 >>> u(-0.25) -0.25 >>> u(0) ValueParseError: Value not in interval - [-inf, 0) expected but 0 found.
Negative integer
>>> u = negative.int() >>> u(-1) -1 >>> u(-0.25) TypeParseError: Value type not match - int expected but float found. >>> u(0) ValueParseError: Value not in interval - [-inf, 0) expected but 0 found.
non_positive¶
-
argsloader.units.numeric.
non_positive
()[source]¶ - Overview:
Check if the value is non-positive.
Similar to
interval.R(0)
. Seeinterval()
.- Examples::
Simple usage
>>> from argsloader.units import non_positive >>> u = non_positive() >>> u(-1) -1 >>> u(0) 0 >>> u(-0.25) -0.25 >>> u(1) ValueParseError: Value not in interval - [-inf, 0] expected but 1 found.
Non-positive integer
>>> u = non_positive.int() >>> u(-1) -1 >>> u(0) 0 >>> u(-0.25) TypeParseError: Value type not match - int expected but float found. >>> u(1) ValueParseError: Value not in interval - [-inf, 0] expected but 1 found.
non_negative¶
-
argsloader.units.numeric.
non_negative
()[source]¶ - Overview:
Check if the value is non-negative.
Similar to
interval.L(0)
. Seeinterval()
.- Examples::
Simple usage
>>> from argsloader.units import non_negative >>> u = non_negative() >>> u(1) 1 >>> u(0) 0 >>> u(0.25) 0.25 >>> u(-1) ValueParseError: Value not in interval - [0, +inf] expected but -1 found.
Non-negative integer
>>> u = non_negative.int() >>> u(1) 1 >>> u(0) 0 >>> u(0.25) TypeParseError: Value type not match - int expected but float found. >>> u(-1) ValueParseError: Value not in interval - [0, +inf] expected but -1 found.
nature¶
-
argsloader.units.numeric.
nature
()[source]¶ - Overview:
Check if the given value is a natural number.
The same as
non_negative.int
, seenon_negative()
.- Examples::
>>> from argsloader.units import nature >>> u = nature() >>> u(1) 1 >>> u(0) 0 >>> u(0.25) TypeParseError: Value type not match - int expected but float found. >>> u(-1) ValueParseError: Value not in interval - [0, +inf] expected but -1 found.
NumberUnit¶
-
class
argsloader.units.numeric.
NumberUnit
[source]¶ - Overview:
A unit for transform all types of number-liked data to number.
-
__init__
()[source]¶ Constructor of class
NumberUnit
.
number¶
-
argsloader.units.numeric.
number
() → argsloader.units.numeric.NumberUnit[source]¶ - Overview:
Get a number unit, used to transform all types of number-liked data to number.
- Returns
Number unit mentioned above.
- Examples::
>>> from argsloader.units import number >>> u = number() >>> u(233) # int 233 >>> u(234.5) # float 234.5 >>> u('233') # int-liked str 233 >>> u('234.5') # float-liked str 234.5 >>> u('0x74f') # hex-liked str 1871 >>> u('0o735') # oct-liked str 477 >>> u('0b1010010011') # bin-liked str 659 >>> u('-inf') # neg-infinite -inf >>> u('nan') # not a number nan
IntLikedUnit¶
-
class
argsloader.units.numeric.
IntLikedUnit
(eps=1e-08)[source]¶ - Overview:
Unit for parsing int-liked number to int.
-
__init__
(eps=1e-08)[source]¶ Constructor of
IntLikedUnit
.- Parameters
eps – Eps tolerance.
int_like¶
-
argsloader.units.numeric.
int_like
(eps=1e-08)[source]¶ - Overview:
Check if the given value is an int-liked value.
- Parameters
eps – Eps tolerance, default is
1e-8
.- Returns
A unit for parsing this kind of number.
- Examples::
>>> from argsloader.units import int_like >>> u = int_like() >>> u(233) 233 >>> u(233.0) 233 >>> u(233.002) ValueParseError: Value expected to be an int-liked number, but 233.002 found.