Modulo · mod
---
config:
flowchart:
useMaxWidth: false
---
flowchart TB
classDef ok fill:#d4edda,stroke:#28a745,color:#000
classDef partial fill:#fff3cd,stroke:#ffc107,color:#000
classDef refused fill:#d4edda,stroke:#28a745,stroke-width:3px,stroke-dasharray: 2 2,color:#000
classDef missing fill:#f8d7da,stroke:#dc3545,color:#000
classDef diverge fill:#cce5ff,stroke:#007bff,color:#000
classDef block fill:#2b3a4a,stroke:#2b3a4a,color:#fff,font-weight:bold
classDef ext fill:#fff,stroke:#666,color:#000,stroke-dasharray: 5 5
O["Modulo · mod<br/>🟢7"]:::ok
subgraph G_ds["Dataset"]
direction LR
v_ds_ds["mod(DS, DS)"]:::ok
v_ds_sc["mod(DS, sc)"]:::ok
v_sc_ds["mod(sc, DS)"]:::ok
end
subgraph G_comp["Component"]
direction LR
v_comp_comp["mod(comp, comp)"]:::ok
v_comp_sc["mod(comp, sc)"]:::ok
v_sc_comp["mod(sc, comp)"]:::ok
end
subgraph G_sc["Scalar"]
direction LR
v_sc_sc["mod(sc, sc)"]:::ok
end
O --- G_ds
O --- G_comp
O --- G_sc
style G_ds fill:#f8f9fa,stroke:#495057,stroke-width:2px
style G_comp fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 8 5
style G_sc fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 2 3
click v_ds_ds href "#form-ds-ds"
click v_ds_sc href "#form-ds-sc"
click v_sc_ds href "#form-sc-ds"
click v_comp_comp href "#form-comp-comp"
click v_comp_sc href "#form-comp-sc"
click v_sc_comp href "#form-sc-comp"
click v_sc_sc href "#form-sc-sc"
Types
Takes number · Gives number
Comes from · number — 44 operators in 6 blocks 🟢44
General purpose operators (2) 🟢2
String operators (3) 🟢3
Numeric operators (17) 🟢17
Time operators (9) 🟢9
Aggregate and Analytic operators (10) 🟢10
Data validation operators (3) 🟢3
Comes from · operators that return any type (their input's) — 37 operators in 8 blocks 🟢37
General purpose operators (5) 🟢5
Join operators (4) 🟢4
Time operators (3) 🟢3
Set operators (4) 🟢4
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (8) 🟢8
Conditional operators (3) 🟢3
Goes to · number — 33 operators in 7 blocks 🟢33
General purpose operators (1) 🟢1
Numeric operators (17) 🟢17
Time operators (2) 🟢2
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (8) 🟢8
Data validation operators (2) 🟢2
Definitions (VTL-DL) (2) 🟢2
Goes to · operators that take any scalar — 48 operators in 8 blocks 🟢48
General purpose operators (6) 🟢6
Join operators (4) 🟢4
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (10) 🟢10
Data validation operators (1) 🟢1
Conditional operators (3) 🟢3
Forms
mod(DS, DS) 🟢 · number → number
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
the remainder of each measure of
DS_1divided by the same measure ofDS_2, on the data points that the two datasets share.- Manual:
Modulo, Example 1, output verbatim: “The operator mod returns the remainder of op1 divided by op2.”
- Expected:
only (10, A) and (11, B) are in both datasets:
100 mod 1 = 0,0.7545 mod 0.25 = 0.0045,9 mod 2 = 1and20.3 mod 2.0 = 0.3.
DS_r := mod ( DS_1, DS_2 );
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 10 | A | 100 | 0.7545 |
| 10 | B | 10 | 18.45 |
| 11 | A | 20 | 1.87 |
| 11 | B | 9 | 20.3 |
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 10 | A | 1 | 0.25 |
| 10 | C | 5 | 3.0 |
| 11 | B | 2 | 2.0 |
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 10 | A | 0 | 0.0045 |
| 11 | B | 1 | 0.3 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · input/DS_2.csv · input/DS_2.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
mod(DS, sc) 🟢 · number → number
Manual example 2 🟢 pandas ✅ · DuckDB ✅
- Tests:
every measure of
DS_1modulo a scalar.- Manual:
Modulo, Example 2, output verbatim: “The operator mod returns the remainder of op1 divided by op2.”
- Expected:
mod(DS_1, 15):100 mod 15 = 10,18.45 mod 15 = 3.45,20 mod 15 = 5and20.3 mod 15 = 5.3; a value under 15 stays as it is.
DS_r := mod ( DS_1, 15 );
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 10 | A | 100 | 0.7545 |
| 10 | B | 10 | 18.45 |
| 11 | A | 20 | 1.87 |
| 11 | B | 9 | 20.3 |
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 10 | A | 10 | 0.7545 |
| 10 | B | 10 | 3.45 |
| 11 | A | 5 | 1.87 |
| 11 | B | 9 | 5.3 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
mod(sc, DS) 🟢 · number → number
Integer and number measures 🟢 pandas ✅ · DuckDB ✅
- Tests:
the remainder of a scalar divided by every measure of a dataset that has an Integer and a Number measure.
- Manual:
Modulo: “The operator mod returns the remainder of op1 divided by op2.”
- Expected:
mod(11, DS_1):Me_1(Integer) 4, 2 and 1;Me_2(Number)11 mod 2.5 = 1.0,11 mod 4.0 = 3.0and11 mod 3.5 = 0.5.
DS_r := mod(11, DS_1);
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 7 | 2.5 |
| 2 | 9 | 4.0 |
| 3 | 10 | 3.5 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 4 | 1.000000 |
| 2 | 2 | 3.000000 |
| 3 | 1 | 0.500000 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
mod(comp, comp) 🟢 · number → number
Integer mod number 🟢 pandas ✅ · DuckDB ✅
- Tests:
the remainder of an Integer component divided by a Number component, inside
calc.- Manual:
Modulo: “If one of the operands is of type number, then the other operand is implicitly cast to number and therefore the result has type number.”
- Expected:
Me_3 = mod(Me_1, Me_2):7 mod 2.5 = 2.0,9 mod 4.0 = 1.0and10 mod 3.5 = 3.0, a Number; the other components are kept.
DS_r := DS_1[calc Me_3 := mod(Me_1, Me_2)];
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 7 | 2.5 |
| 2 | 9 | 4.0 |
| 3 | 10 | 3.5 |
| Id_1 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|
| 1 | 7 | 2.500000 | 2.000000 |
| 2 | 9 | 4.000000 | 1.000000 |
| 3 | 10 | 3.500000 | 3.000000 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
mod(comp, sc) 🟢 · number → number
Manual example 3 🟢 pandas ✅ · DuckDB ✅
- Tests:
modon a component insidecalc, with a Number divisor.- Manual:
Modulo, Example 3, output verbatim: “The operator mod returns the remainder of op1 divided by op2.”
- Expected:
Me_3 = mod(Me_1, 3.0)is 1.0, 1.0, 2.0 and 0.0, a Number; the other components are kept.
DS_r := DS_1[ calc Me_3 := mod( Me_1, 3.0 ) ];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 10 | A | 100 | 0.7545 |
| 10 | B | 10 | 18.45 |
| 11 | A | 20 | 1.87 |
| 11 | B | 9 | 20.3 |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|---|
| 10 | A | 100 | 0.7545 | 1.0 |
| 10 | B | 10 | 18.45 | 1.0 |
| 11 | A | 20 | 1.87 | 2.0 |
| 11 | B | 9 | 20.3 | 0.0 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
mod(sc, comp) 🟢 · number → number
Integer mod integer 🟢 pandas ✅ · DuckDB ✅
- Tests:
the remainder of a scalar divided by an Integer component, inside
calc.- Manual:
Modulo: “If the type of both operands is integer then the result has type integer.”
- Expected:
Me_3 = mod(11, Me_1):11 mod 7 = 4,11 mod 9 = 2and11 mod 10 = 1, an Integer; the other components are kept.
DS_r := DS_1[calc Me_3 := mod(11, Me_1)];
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 7 | 2.5 |
| 2 | 9 | 4.0 |
| 3 | 10 | 3.5 |
| Id_1 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|
| 1 | 7 | 2.500000 | 4 |
| 2 | 9 | 4.000000 | 2 |
| 3 | 10 | 3.500000 | 1 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
mod(sc, sc) 🟢 · number → number
Positive operands 🟢 pandas ✅ · DuckDB ✅
- Tests:
the remainder of two positive integers:
mod(SC_1, SC_2)withSC_1= 5 andSC_2= 2.- Manual:
Modulo: “
mod ( 5, 2 )gives1”.- Expected:
SC_r = 1, an Integer.
SC_r := mod(SC_1, SC_2);
| SC_1 | SC_2 |
|---|---|
| 5 | 2 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
Negative divisor 🟢 pandas ✅ · DuckDB ✅
- Tests:
the sign of the remainder when the divisor is negative:
mod(SC_1, SC_2)withSC_1= 5 andSC_2= -2.- Manual:
Modulo: “
mod ( 5, -2 )gives-1”.- Expected:
SC_r = -1, an Integer: the remainder takes the sign of the divisor.
SC_r := mod(SC_1, SC_2);
| SC_1 | SC_2 |
|---|---|
| 5 | -2 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
Zero divisor 🟢 pandas ✅ · DuckDB ✅
- Tests:
the result when the divisor is 0:
mod(SC_1, SC_2)withSC_1= 9 andSC_2= 0.- Manual:
Modulo: “It returns op1 if divisor op2 is 0”, and “
mod ( 9, 0 )gives9”.- Expected:
SC_r = 9, an Integer.
SC_r := mod(SC_1, SC_2);
| SC_1 | SC_2 |
|---|---|
| 9 | 0 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗