Type conversion · cast

🟢 41 of 41 forms all ok · VTL 2.2 Reference Manual ↗ · vtlengine 1.10.0rc3 (9e1c81a6) · pandas 2.3.3 · DuckDB 1.5.5
🟢 all ok🟡 partially implemented🛡️ refused with an error🔴 not implemented or crash🔵 engines differ ✅ match · ❌ wrong result · 🛡 guarded error (code) · 💥 crash · 📌 team decision
Dataset formsComponent formsScalar forms
        ---
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["Type conversion · cast 📌<br/>🟢41"]:::ok
    subgraph G_ds["Dataset"]
        direction LR
        v_string_to_integer_ds["cast(DS#60;string#62;, integer)"]:::ok
    end
    subgraph G_comp["Component"]
        direction LR
        v_integer_to_boolean["cast(comp#60;integer#62;, boolean)"]:::ok
        v_number_to_boolean["cast(comp#60;number#62;, boolean)"]:::ok
        v_boolean_to_integer["cast(comp#60;boolean#62;, integer)"]:::ok
        v_boolean_to_number["cast(comp#60;boolean#62;, number)"]:::ok
        v_time_to_date["cast(comp#60;time#62;, date)"]:::ok
        v_time_to_time_period["cast(comp#60;time#62;, time_period)"]:::ok
        v_date_to_time_period["cast(comp#60;date#62;, time_period)"]:::ok
        v_time_period_to_date["cast(comp#60;time_period#62;, date)"]:::ok
        v_string_to_boolean["cast(comp#60;string#62;, boolean)"]:::ok
        v_integer_to_number["cast(comp#60;integer#62;, number)"]:::ok
        v_boolean_to_string["cast(comp#60;boolean#62;, string)"]:::ok
        v_date_to_time["cast(comp#60;date#62;, time)"]:::ok
        v_time_period_to_time["cast(comp#60;time_period#62;, time)"]:::ok
        v_integer_to_string["cast(comp#60;integer#62;, string)"]:::ok
        v_integer_to_string_mask["cast(comp#60;integer#62;, string, mask)"]:::ok
        v_number_to_string["cast(comp#60;number#62;, string)"]:::ok
        v_number_to_string_mask["cast(comp#60;number#62;, string, mask)"]:::ok
        v_time_to_string["cast(comp#60;time#62;, string)"]:::ok
        v_time_to_string_mask["cast(comp#60;time#62;, string, mask)"]:::ok
        v_date_to_string["cast(comp#60;date#62;, string)"]:::ok
        v_date_to_string_mask["cast(comp#60;date#62;, string, mask)"]:::ok
        v_time_period_to_string["cast(comp#60;time_period#62;, string) 📌"]:::ok
        v_time_period_to_string_mask["cast(comp#60;time_period#62;, string, mask)"]:::ok
        v_duration_to_string["cast(comp#60;duration#62;, string)"]:::ok
        v_duration_to_string_mask["cast(comp#60;duration#62;, string, mask)"]:::ok
        v_string_to_integer["cast(comp#60;string#62;, integer)"]:::ok
        v_string_to_integer_mask["cast(comp#60;string#62;, integer, mask)"]:::ok
        v_string_to_number["cast(comp#60;string#62;, number)"]:::ok
        v_string_to_number_mask["cast(comp#60;string#62;, number, mask)"]:::ok
        v_string_to_time["cast(comp#60;string#62;, time)"]:::ok
        v_string_to_time_mask["cast(comp#60;string#62;, time, mask)"]:::ok
        v_string_to_date["cast(comp#60;string#62;, date)"]:::ok
        v_string_to_date_mask["cast(comp#60;string#62;, date, mask)"]:::ok
        v_string_to_time_period["cast(comp#60;string#62;, time_period)"]:::ok
        v_string_to_time_period_mask["cast(comp#60;string#62;, time_period, mask)"]:::ok
        v_string_to_duration["cast(comp#60;string#62;, duration)"]:::ok
        v_string_to_duration_mask["cast(comp#60;string#62;, duration, mask)"]:::ok
        v_string_to_value_domain["cast(comp#60;string#62;, VD)"]:::ok
        v_value_domain_to_value_domain["cast(comp#60;VD#62;, VD)"]:::ok
    end
    subgraph G_sc["Scalar"]
        direction LR
        v_string_to_integer_sc["cast(sc#60;string#62;, integer)"]:::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_integer_to_boolean href "#form-integer-to-boolean"
    click v_number_to_boolean href "#form-number-to-boolean"
    click v_boolean_to_integer href "#form-boolean-to-integer"
    click v_boolean_to_number href "#form-boolean-to-number"
    click v_time_to_date href "#form-time-to-date"
    click v_time_to_time_period href "#form-time-to-time-period"
    click v_date_to_time_period href "#form-date-to-time-period"
    click v_time_period_to_date href "#form-time-period-to-date"
    click v_string_to_boolean href "#form-string-to-boolean"
    click v_integer_to_number href "#form-integer-to-number"
    click v_boolean_to_string href "#form-boolean-to-string"
    click v_date_to_time href "#form-date-to-time"
    click v_time_period_to_time href "#form-time-period-to-time"
    click v_integer_to_string href "#form-integer-to-string"
    click v_integer_to_string_mask href "#form-integer-to-string-mask"
    click v_number_to_string href "#form-number-to-string"
    click v_number_to_string_mask href "#form-number-to-string-mask"
    click v_time_to_string href "#form-time-to-string"
    click v_time_to_string_mask href "#form-time-to-string-mask"
    click v_date_to_string href "#form-date-to-string"
    click v_date_to_string_mask href "#form-date-to-string-mask"
    click v_time_period_to_string href "#form-time-period-to-string"
    click v_time_period_to_string_mask href "#form-time-period-to-string-mask"
    click v_duration_to_string href "#form-duration-to-string"
    click v_duration_to_string_mask href "#form-duration-to-string-mask"
    click v_string_to_integer href "#form-string-to-integer"
    click v_string_to_integer_mask href "#form-string-to-integer-mask"
    click v_string_to_number href "#form-string-to-number"
    click v_string_to_number_mask href "#form-string-to-number-mask"
    click v_string_to_time href "#form-string-to-time"
    click v_string_to_time_mask href "#form-string-to-time-mask"
    click v_string_to_date href "#form-string-to-date"
    click v_string_to_date_mask href "#form-string-to-date-mask"
    click v_string_to_time_period href "#form-string-to-time-period"
    click v_string_to_time_period_mask href "#form-string-to-time-period-mask"
    click v_string_to_duration href "#form-string-to-duration"
    click v_string_to_duration_mask href "#form-string-to-duration-mask"
    click v_string_to_integer_ds href "#form-string-to-integer-ds"
    click v_string_to_integer_sc href "#form-string-to-integer-sc"
    click v_string_to_value_domain href "#form-string-to-value-domain"
    click v_value_domain_to_value_domain href "#form-value-domain-to-value-domain"
    

Types

Takes number, integer, string, boolean, time, date, time_period, duration, value domain, any scalar · Gives number, integer, string, boolean, time, date, time_period, duration, any type

Comes from: any operator that returns a value

Comes from · value domain: none

Goes to: whatever takes its input's type

Goes to · number, integer, string, boolean, time, date, time_period, duration — 78 operators in 12 blocks 🟢78
Join operators (4) 🟢4
String operators (11) 🟢11
Numeric operators (18) 🟢18
Comparison operators (1) 🟢1
Boolean operators (4) 🟢4
Time operators (16) 🟢16
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (13) 🟢13
Data validation operators (2) 🟢2
Conditional operators (2) 🟢2
Clause operators (2) 🟢2
Definitions (VTL-DL) (4) 🟢4
Goes to · operators that take any scalar — 35 operators in 7 blocks 🟢35
General purpose operators (6) 🟢6
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (5) 🟢5
Data validation operators (1) 🟢1
Conditional operators (1) 🟢1
Clause operators (7) 🟢7

Forms

cast(DS<string>, integer) 🟢 · string → integer

Default measure name 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(DS_1, integer) on a dataset with one String measure.

Manual:

Operators changing the data type: “the operators changing the data type are allowed only on mono-measure operand Data Sets […]. A default generic Measure is assigned by default to the result Data Set, depending on the data type of the result”, int_var for an integer.

Expected:

Id_1 and the measure int_var, 42 and -7 by the rule of Type conversion: “a sequence of digits is consumed to determine its absolute value”.

script.vtl
DS_r := cast(DS_1, integer);
Input DS_1
Id_1Me_1
142
2-7
Expected DS_r
Id_1int_var
142
2-7

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<integer>, boolean) 🟢 · integer → boolean

Zero and non zero 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, boolean) on an Integer measure, an explicit cast without mask.

Manual:

Type conversion: “From integer to boolean: if the integer value is not equal to zero, then the boolean true literal is returned, in every other case the boolean false literal is returned.”

Expected:

0 gives false; 7 and -2 give true.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, boolean)];
Input DS_1
Id_1Me_1
10
27
3-2
Expected DS_r
Id_1Me_1Me_2
10false
27true
3-2true

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<number>, boolean) 🟢 · number → boolean

Zero and non zero 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, boolean) on a Number measure, an explicit cast without mask.

Manual:

Type conversion: “From number to boolean: if the number absolute value is not equal to zero, then the boolean true literal is returned, in every other case the boolean false literal is returned.”

Expected:

0.0 gives false; 0.5 and -3.25 give true.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, boolean)];
Input DS_1
Id_1Me_1
10.0
20.5
3-3.25
Expected DS_r
Id_1Me_1Me_2
10.0false
20.5true
3-3.25true

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<boolean>, integer) 🟢 · boolean → integer

True and false 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, integer) on a Boolean measure, an explicit cast without mask.

Manual:

Type conversion: “From boolean to integer: the integer 0 is returned if the boolean value is false, 1 if its true.”

Expected:

true gives 1 and false gives 0.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, integer)];
Input DS_1
Id_1Me_1
1true
2false
Expected DS_r
Id_1Me_1Me_2
1true1
2false0

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<boolean>, number) 🟢 · boolean → number

True and false 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, number) on a Boolean measure, an explicit cast without mask.

Manual:

Type conversion: “From boolean to number: the number 0.0 is returned if the boolean value is false, 1.0 if its true.”

Expected:

true gives 1.0 and false gives 0.0.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, number)];
Input DS_1
Id_1Me_1
1true
2false
Expected DS_r
Id_1Me_1Me_2
1true1.0
2false0.0

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<time>, date) 🟢 · time → date

Single day intervals 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, date) on a Time measure whose intervals start and end on the same day, an explicit cast without mask.

Manual:

Type conversion: “From time to date: A date value is returned if the time value start and ends at the same date, otherwise an error is raised.”

Expected:

2020-01-15 and 2021-12-31; neither raises the error.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, date)];
Input DS_1
Id_1Me_1
12020-01-15/2020-01-15
22021-12-31/2021-12-31
Expected DS_r
Id_1Me_1Me_2
12020-01-15/2020-01-152020-01-15
22021-12-31/2021-12-312021-12-31

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<time>, time_period) 🟢 · time → time_period

Year quarter and month 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, time_period) on a Time measure of a whole year, a quarter and a month, an explicit cast without mask.

Manual:

Type conversion: “From time to time_period: A time_period value is returned if the time value has a regular duration (see above for its meaning) otherwise an error is raised.” Nothing above defines it: the inputs have the durations that the page accepts for a period parsed from an interval, “an entire year, a half of a year, a quarter of a year or a month”.

Expected:

2020A, 2020Q2 and 2020M07, the comparison taking 2020A and 2020 as the same period.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, time_period)];
Input DS_1
Id_1Me_1
12020-01-01/2020-12-31
22020-04-01/2020-06-30
32020-07-01/2020-07-31
Expected DS_r
Id_1Me_1Me_2
12020-01-01/2020-12-312020A
22020-04-01/2020-06-302020Q2
32020-07-01/2020-07-312020M07

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<date>, time_period) 🟢 · date → time_period

Daily periods 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, time_period) on a Date measure, an explicit cast without mask.

Manual:

Type conversion: “From date to time_period: A time_period value with a daily duration is returned, starting and ending at the specified date value.”

Expected:

Daily periods, written YYYYD and the day of the year: 2020D15, 2020D61 for March 1st, after the 31 days of January and the 29 of February, and 2021D365, 2021 not being a leap year.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, time_period)];
Input DS_1
Id_1Me_1
12020-01-15
22020-03-01
32021-12-31
Expected DS_r
Id_1Me_1Me_2
12020-01-152020D15
22020-03-012020D61
32021-12-312021D365

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<time_period>, date) 🟢 · time_period → date

Daily periods 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, date) on a Time_Period measure of daily periods, an explicit cast without mask.

Manual:

Type conversion: “From time_period to date: A date value is returned if the input time_period has a duration of a single day, representing that day; otherwise an error is raised.”

Expected:

2020D15 gives 2020-01-15 and 2020D61 gives 2020-03-01, 2020 being a leap year; both are daily, so neither raises the error.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, date)];
Input DS_1
Id_1Me_1
12020D15
22020D61
Expected DS_r
Id_1Me_1Me_2
12020D152020-01-15
22020D612020-03-01

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Non daily period 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, date) on a Time_Period measure whose period, 2020Q1, is not a single day: the first error that the page states for a conversion between basic scalar types.

Manual:

Type conversion: “From time_period to date: A date value is returned if the input time_period has a duration of a single day, representing that day; otherwise an error is raised.”

Expected:

The error 2-1-5-1, “Impossible to cast {value} from type {type_1} to {type_2}.”, as 2020Q1 lasts a quarter, not a single day: “otherwise an error is raised”.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, date)];
Input DS_1
Id_1Me_1
12020Q1

Expected error 2-1-5-1: Impossible to cast {value} from type {type_1} to {type_2}.

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/error.json · example page ↗

cast(comp<string>, boolean) 🟢 · string → boolean

True in any case 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, boolean) on a String measure, an explicit cast without mask: true in any case.

Manual:

Type conversion: “From string to boolean: The boolean value representing true is returned if the input string, with any leading or trailing blanks removed, is equal to "true" not considering the case. The boolean value representing false is returned in any other case.”

Expected:

true and TRUE give true, and false gives false.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, boolean)];
Input DS_1
Id_1Me_1
1true
2TRUE
3false
Expected DS_r
Id_1Me_1Me_2
1truetrue
2TRUEtrue
3falsefalse

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Other strings are false 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, boolean) on strings that are neither true nor false.

Manual:

Type conversion: the boolean true is returned if the string “is equal to "true" not considering the case”, and “The boolean value representing false is returned in any other case.”

Expected:

yes and 1 give false: the rule compares with the text true only. The strings have no blanks around them, as the loading of blanks is not what the example tests.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, boolean)];
Input DS_1
Id_1Me_1
1yes
21
Expected DS_r
Id_1Me_1Me_2
1yesfalse
21false

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<integer>, number) 🟢 · integer → number

Zero decimal part 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, number) on an Integer measure, an implicit conversion written as an explicit cast, whose “behavior remains the same”.

Manual:

Type conversion: “From integer to number: a number value is returned having the integer part equal to the integer value, and the decimal part equal to zero.”

Expected:

5 gives 5.0 and -3 gives -3.0.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, number)];
Input DS_1
Id_1Me_1
15
2-3
Expected DS_r
Id_1Me_1Me_2
155.0
2-3-3.0

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<boolean>, string) 🟢 · boolean → string

True and false 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, string) on a Boolean measure, an implicit conversion written as an explicit cast, whose “behavior remains the same”.

Manual:

Type conversion: “From boolean to string: Either one of the string values "true" and "false" is returned, depending on the input.”

Expected:

true gives the string true and false gives false, in lower case as the manual writes them; a string is compared exactly.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, string)];
Input DS_1
Id_1Me_1
1true
2false
Expected DS_r
Id_1Me_1Me_2
1truetrue
2falsefalse

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<date>, time) 🟢 · date → time

Same start and end 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, time) on a Date measure, an implicit conversion written as an explicit cast, whose “behavior remains the same”.

Manual:

Type conversion: “From date to time: a time value is returned having its start equal to its end, and both equal to the input date value.”

Expected:

2020-01-15/2020-01-15 and 2021-12-31/2021-12-31, a time written start/end, as vtlengine reads it.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, time)];
Input DS_1
Id_1Me_1
12020-01-15
22021-12-31
Expected DS_r
Id_1Me_1Me_2
12020-01-152020-01-15/2020-01-15
22021-12-312021-12-31/2021-12-31

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<time_period>, time) 🟢 · time_period → time

Start and end of the period 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, time) on a Time_Period measure: a time from the start to the end of each period, an implicit conversion written as an explicit cast, whose “behavior remains the same”.

Manual:

Type conversion: “From time_period to time: a time value is returned having the stame start and end of the input time_period value.”

Expected:

2020Q1 gives 2020-01-01/2020-03-31 and 2021M02 gives 2021-02-01/2021-02-28, 2021 not being a leap year: a time written start/end, as vtlengine reads it.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, time)];
Input DS_1
Id_1Me_1
12020Q1
22021M02
Expected DS_r
Id_1Me_1Me_2
12020Q12020-01-01/2020-03-31
22021M022021-02-01/2021-02-28

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<integer>, string) 🟢 · integer → string

Digits and sign 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, string) on an Integer measure, without a mask: the default format.

Manual:

Type conversion: “From integer: the integer value is printed as a sequence of digits, without any leading zeroes or thousands separators, possibly preceded by a -.”

Expected:

1500 with no thousands separator, -7 preceded by -, and 0.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, string)];
Input DS_1
Id_1Me_1
11500
2-7
30
Expected DS_r
Id_1Me_1Me_2
115001500
2-7-7
300

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<integer>, string, mask) 🟢 · integer, string → string

Two digit mask 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, string, "DD") on an Integer measure: a number mask of two digits.

Manual:

Type Conversion and Formatting Mask: ““D” one numeric digit (for the mantissa of the scientific notation)”.

Expected:

42 and 17, and 07 from 7: the mask writes a digit for each D, so a value of one digit gets a leading zero, which the conversion without a mask does not write.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "DD")];
Input DS_1
Id_1Me_1
142
217
37
Expected DS_r
Id_1Me_1Me_2
14242
21717
3707

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<number>, string) 🟢 · number → string

Plain decimal notation 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, string) on a Number measure, without a mask: the default format.

Manual:

Type conversion: “From number: the number value may be printed either in the scientific notation, or as a sequence of digits, possibly preceded by a -, with . as the decimal separator, without any leading zeroes or thousands separators.”

Expected:

The sequence of digits, 3.5 and -12.75, values exact in binary floating point; they are not between -1 and 1, so the reading of “without any leading zeroes” (0.5 or .5) does not matter. A scientific result, which the manual allows too, would not match these strings.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, string)];
Input DS_1
Id_1Me_1
13.5
2-12.75
Expected DS_r
Id_1Me_1Me_2
13.53.5
2-12.75-12.75

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<number>, string, mask) 🟢 · number, string → string

Decimal mask 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, string, "DD.DDD") on a Number measure: the mask of the page’s Example 1.

Manual:

Type Conversion and Formatting Mask: ““D” one numeric digit (for the mantissa of the scientific notation)” and ““.” (dot) can be used as a separator between the integer and the decimal parts”.

Expected:

12.375 and 40.125, and 03.500 from 3.5: two digits, a dot and three digits, a digit for each D, so 3.5 gets a leading zero and two trailing zeros, which the conversion without a mask does not write. The values are exact in binary floating point, so none is rounded.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "DD.DDD")];
Input DS_1
Id_1Me_1
112.375
240.125
33.5
Expected DS_r
Id_1Me_1Me_2
112.37512.375
240.12540.125
33.503.500

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<time>, string) 🟢 · time → string

Iso 8601 intervals 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, string) on a Time measure, without a mask: the default format.

Manual:

Type conversion: “From time: the time value is printed using the ISO-8601 representation for generic time intervals, up to a maximum of day precision, in the form start/end.”

Expected:

2020-01-01/2020-06-30 and 2021-03-15/2021-03-20, with the dates in the ISO-8601 extended form YYYY-MM-DD.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, string)];
Input DS_1
Id_1Me_1
12020-01-01/2020-06-30
22021-03-15/2021-03-20
Expected DS_r
Id_1Me_1Me_2
12020-01-01/2020-06-302020-01-01/2020-06-30
22021-03-15/2021-03-202021-03-15/2021-03-20

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<time>, string, mask) 🟢 · time, string → string

Start and end mask 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, string, "YYYY-MM-DD/YYYY-MM-DD") on a Time measure: the mask that the manual gives for a time with “Start and end”, to the day, also on a time whose start and end have times of day.

Manual:

Type Conversion and Formatting Mask: “Example of other possible ISO formats having accuracy reduced to the day”, “The number of letters matches the number of digits”, and “Any other character can be used in the mask, meaning simply that it appears in the same position”.

Expected:

2015-03-03/2018-04-05 and 2020-01-01/2020-06-30, and 2015-03-03/2018-04-05 for the time from 2015-03-03T09:30:45 to 2018-04-05T12:30:15: the mask has no hours, minutes or seconds. The manual’s sample value, 20150303/20180405, has no -, which its mask has: the example follows the mask. By the manual, the conversion without a mask prints a time “up to a maximum of day precision”, the same text: no value tells the mask apart, but vtlengine keeps the times of day, which the third data point shows.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "YYYY-MM-DD/YYYY-MM-DD")];
Input DS_1
Id_1Me_1
12015-03-03/2018-04-05
22020-01-01/2020-06-30
32015-03-03T09:30:45/2018-04-05T12:30:15
Expected DS_r
Id_1Me_1Me_2
12015-03-03/2018-04-052015-03-03/2018-04-05
22020-01-01/2020-06-302020-01-01/2020-06-30
32015-03-03T09:30:45/2018-04-05T12:30:152015-03-03/2018-04-05

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<date>, string) 🟢 · date → string

Iso 8601 dates 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, string) on a Date measure, without a mask: the default format.

Manual:

Type conversion: “From date: the date value is printed using the ISO-8601 representation for dates, with the year, month and day of month fields always present.”

Expected:

The ISO-8601 extended form YYYY-MM-DD: 2020-01-15 and 2021-12-31.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, string)];
Input DS_1
Id_1Me_1
12020-01-15
22021-12-31
Expected DS_r
Id_1Me_1Me_2
12020-01-152020-01-15
22021-12-312021-12-31

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<date>, string, mask) 🟢 · date, string → string

Year month day mask 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, string, "YYYYMMDD") on a Date measure: four digits for the year, two for the month and two for the day.

Manual:

Type Conversion and Formatting Mask: “YYYMMDD means four digits for the year followed by two digits for the month and then two digits for the day (e.g., 20180405 means the year 2018, month April, day 5th)”, and “The number of letters matches the number of digits”.

Expected:

20180405 and 20200115. The manual’s YYYMMDD has three Y for four digits; the mask has one per digit.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "YYYYMMDD")];
Input DS_1
Id_1Me_1
12018-04-05
22020-01-15
Expected DS_r
Id_1Me_1Me_2
12018-04-0520180405
22020-01-1520200115

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Optional digits 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, string, "{D}D/{M}M/YYYY") on a Date measure: braces around the digit of the day and of the month that may be left out.

Manual:

Type Conversion and Formatting Mask: “If the numerical representation is not padded, the optional digits that can be omitted (if equal to zero) are enclosed within braces; for example {M}M means that April is represented by 4 and December by 12”.

Expected:

5/4/2018, 31/12/2021 and 15/1/2020: a day or a month below 10 is written with one digit, where DD and MM would pad it with a zero.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "{D}D/{M}M/YYYY")];
Input DS_1
Id_1Me_1
12018-04-05
22021-12-31
32020-01-15
Expected DS_r
Id_1Me_1Me_2
12018-04-055/4/2018
22021-12-3131/12/2021
32020-01-1515/1/2020

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Date and time with separators 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, string, "YYYY-MM-DDThh:mm:ssZ") on a Date measure with a time of day: the manual’s mask for a “Date and day time with separators”.

Manual:

Type Conversion and Formatting Mask: “A date scalar type is a point in time”, “Date and day time with separators: “2015-03-03T09:30:45Z”” with the mask YYYY-MM-DDThh:mm:ssZ, and T and Z are among the “fixed characters used in the ISO 8601 standard which can appear as fixed characters in the relevant masks”.

Expected:

2015-03-03T09:30:45Z, the manual’s value, and 2018-04-05T12:30:15Z. Z is a fixed character: the time is written as it is.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "YYYY-MM-DDThh:mm:ssZ")];
Input DS_1
Id_1Me_1
12015-03-03T09:30:45
22018-04-05T12:30:15
Expected DS_r
Id_1Me_1Me_2
12015-03-03T09:30:452015-03-03T09:30:45Z
22018-04-05T12:30:152018-04-05T12:30:15Z

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<time_period>, string) 🟢 · time_period → string

Start and end dates 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, string) on a Time_Period measure, without a mask: the default format.

Manual:

Type conversion: “From time_period: the time_period value is printed using the ISO-8601 representation for generic time intervals, up to a precision of days, in the form start/end.”

Expected:

the period codes: 2020Q1 gives 2020Q1 and 2021M02 gives 2021M2; a string is compared exactly.

Team decision:

#1254: the text of cast follows the pandas engine, which writes the period code, where the manual prints the interval start/end (2020-01-01/2020-03-31).

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, string)];
Input DS_1
Id_1Me_1
12020Q1
22021M02
Expected DS_r
Id_1Me_1Me_2
12020Q12020Q1
22021M022021M2

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<time_period>, string, mask) 🟢 · time_period, string → string

Monthly period mask 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, string, "YYYY\MMM") on a Time_Period measure: the mask that the manual gives for a “Monthly period”.

Manual:

Type Conversion and Formatting Mask: special characters “prefixed by the reverse slash […] appear in the same position”, so \M is the letter M, and “MM that the month is of 2 digits”.

Expected:

2015M03, as in the manual, and 2020M11. Only the mask explains the 0 of 2015M03: without a mask, a period is printed as its interval, start/end, where vtlengine prints its code, 2015M3 (start_and_end_dates).

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "YYYY\MMM")];
Input DS_1
Id_1Me_1
12015M03
22020M11
Expected DS_r
Id_1Me_1Me_2
12015M032015M03
22020M112020M11

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<duration>, string) 🟢 · duration → string

Iso 8601 durations 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, string) on a Duration measure, without a mask: the default format.

Manual:

Type conversion: “From duration: the duration value is printed using the ISO-8601 representation for durations.”

Expected:

The inputs are the one-letter codes that vtlengine reads (“A Year”, “M Month”, “D Day” in the mask section), and one year, month and day are P1Y, P1M and P1D in ISO-8601.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, string)];
Input DS_1
Id_1Me_1
1A
2M
3D
Expected DS_r
Id_1Me_1Me_2
1AP1Y
2MP1M
3DP1D

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<duration>, string, mask) 🟢 · duration, string → string

Period indicator mask 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, string, "P") on a Duration measure: the one-character mask of a duration, with each of its codes.

Manual:

Type Conversion and Formatting Mask: “Non ISO representation of the duration in one character, whose possible codes are”: “D Day”, “W Week”, “M Month”, “Q Quarter”, “S Semester” and “A Year”, with “VTL Mask: P (period indicator)”.

Expected:

The codes A, M, D, W, Q and S. Only the mask explains them: without it, a duration is printed in ISO 8601, such as P1Y for a year.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "P")];
Input DS_1
Id_1Me_1
1A
2M
3D
4W
5Q
6S
Expected DS_r
Id_1Me_1Me_2
1AA
2MM
3DD
4WW
5QQ
6SS

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Number of periods 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, string, "\PppP") on a Duration measure: the “ISO 4 characters representation” of a duration.

Manual:

Type Conversion and Formatting Mask: “ISO 4 characters representation: P10M (ten months), P02Q (two quarters) …”, with “VTL Mask: \PppP”, and “the letter p denotes the number of periods”.

Expected:

P01M, one month, and P01Q, one quarter: a P, the number of periods in two digits and the period indicator. Only the mask explains them: without it, a duration is printed in ISO 8601: P1M for a month, and no Q for a quarter.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, string, "\PppP")];
Input DS_1
Id_1Me_1
1M
2Q
Expected DS_r
Id_1Me_1Me_2
1MP01M
2QP01Q

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<string>, integer) 🟢 · string → integer

Signs leading zeros and null 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, integer) on a String measure, without a mask: signs, leading zeroes and a null.

Manual:

Type conversion: “First a + or - is possibly consumed to determine the sign of the integer […] Finally, a sequence of digits is consumed to determine its absolute value; leading zeroes are skipped”, and “a null input string is converted to the corresponding null value of the desired value domain”.

Expected:

42, -7, 7 from +007, and null from the empty field. The inputs have no blanks for the conversion to remove.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, integer)];
Input DS_1
Id_1Me_1
142
2-7
3+007
4
Expected DS_r
Id_1Me_1Me_2
14242
2-7-7
3+0077
4

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<string>, integer, mask) 🟢 · string → integer

Two digit mask 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, integer, "DD") on a String measure: a number mask of two digits.

Manual:

Type Conversion and Formatting Mask: ““D” one numeric digit (for the mantissa of the scientific notation)”.

Expected:

42, and 7 from 07: each value has as many digits as the mask. The conversion without a mask, which skips leading zeroes, gives the same: the mask shows in the strings that it refuses, such as 7 or 123.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, integer, "DD")];
Input DS_1
Id_1Me_1
142
207
Expected DS_r
Id_1Me_1Me_2
14242
2077

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<string>, number) 🟢 · string → number

Sign decimals and exponent 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, number) on a String measure, without a mask: a sign, decimals, an exponent and no decimal part.

Manual:

Type conversion, “To number”: a sign “is possibly consumed”, then the integer part, then “a . is possibly consumed; if it’s not present, the parsing ends and the number is returned without a decimal part”, then the decimal part, and “E is possibly consumed to determine if a base-ten exponent is present”.

Expected:

3.25, -0.5, 150 from 1.5E2, and 2 from +2. By the rule an exponent needs a . before it, which 1.5E2 has; the inputs have no blanks for the conversion to remove.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, number)];
Input DS_1
Id_1Me_1
13.25
2-0.5
31.5E2
4+2
Expected DS_r
Id_1Me_1Me_2
13.253.25
2-0.5-0.5
31.5E2150
4+22

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<string>, number, mask) 🟢 · string → number

Decimal mask 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, number, "DD.DDD") on a String measure: the mask of the page’s Example 1, cast(m1, number, "DD.DDD") + 2.

Manual:

Type Conversion and Formatting Mask: ““D” one numeric digit (for the mantissa of the scientific notation)” and ““.” (dot) can be used as a separator between the integer and the decimal parts”.

Expected:

12.375, and 3.5 from 03.500: two digits, a dot and three digits. The conversion without a mask, which skips leading zeroes, gives the same: the mask shows in the strings that it refuses, such as 12.5 or 12.3755.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, number, "DD.DDD")];
Input DS_1
Id_1Me_1
112.375
203.500
Expected DS_r
Id_1Me_1Me_2
112.37512.375
203.5003.5

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Decimal comma mask 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, number, "DD,DDD") on a String measure: the mask of the page’s Example 1, with a comma for the dot.

Manual:

Type Conversion and Formatting Mask: ““,” (comma) can be used as a separator between the integer and the decimal parts.”

Expected:

12.375 from 12,375, and 3.5 from 03,500: two digits, a comma and three digits. The conversion without a mask takes a dot only, so it would leave ,375 and ,500 unconsumed, an error.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, number, "DD,DDD")];
Input DS_1
Id_1Me_1
112,375
203,500
Expected DS_r
Id_1Me_1Me_2
112,37512.375
203,5003.5

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<string>, time) 🟢 · string → time

Iso 8601 intervals 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, time) on a String measure, without a mask: ISO-8601 intervals.

Manual:

Type conversion: “To time: the input string is parsed, according to the ISO-8601 standard for time intervals, up to a precision of days, and the corresponding time value is returned.”

Expected:

2020-01-01/2020-06-30 and 2021-03-15/2021-03-20, a time written start/end, as vtlengine reads it. The inputs have no blanks for the conversion to remove.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, time)];
Input DS_1
Id_1Me_1
12020-01-01/2020-06-30
22021-03-15/2021-03-20
Expected DS_r
Id_1Me_1Me_2
12020-01-01/2020-06-302020-01-01/2020-06-30
22021-03-15/2021-03-202021-03-15/2021-03-20

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<string>, time, mask) 🟢 · string → time

Start and end mask 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, time, "YYYY-MM-DD/YYYY-MM-DD") on a String measure: the mask that the manual gives for a time with “Start and end”.

Manual:

Type Conversion and Formatting Mask: “The number of letters matches the number of digits”, and “Any other character can be used in the mask, meaning simply that it appears in the same position”.

Expected:

2015-03-03/2018-04-05 and 2020-01-01/2020-06-30. The manual’s sample value for this mask, 20150303/20180405, has no -; the inputs follow the mask. They are ISO 8601 intervals that the conversion reads without a mask as well, so no value tells the two apart.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, time, "YYYY-MM-DD/YYYY-MM-DD")];
Input DS_1
Id_1Me_1
12015-03-03/2018-04-05
22020-01-01/2020-06-30
Expected DS_r
Id_1Me_1Me_2
12015-03-03/2018-04-052015-03-03/2018-04-05
22020-01-01/2020-06-302020-01-01/2020-06-30

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<string>, date) 🟢 · string → date

Iso 8601 dates 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, date) on a String measure, without a mask: the default parsing.

Manual:

Type conversion, “To date”: “exactly four digits are consumed to determine the year”, then a -, “exactly two digits are consumed to determine the month in the range 01-12”, a - again, and “exactly two digits are consumed to determine the day of the month”.

Expected:

2020-01-15 and 2021-12-31. The inputs have no blanks for the conversion to remove.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, date)];
Input DS_1
Id_1Me_1
12020-01-15
22021-12-31
Expected DS_r
Id_1Me_1Me_2
12020-01-152020-01-15
22021-12-312021-12-31

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<string>, date, mask) 🟢 · string → date

Year month day mask 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, date, "YYYY-MM-DD") on a String measure: the mask of the page’s Example 2, cast(m1, date, "YYYY-MM-DD").

Manual:

Type Conversion and Formatting Mask: “The number of letters matches the number of digits, for example YYYY means that the year is represented with four digits and MM that the month is of 2 digits”, and “Any other character can be used in the mask, meaning simply that it appears in the same position”.

Expected:

The dates 2020-01-15 and 2021-12-31. The mask is the format that the conversion reads without a mask, so no value tells the two apart: the other masks of this form do.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, date, "YYYY-MM-DD")];
Input DS_1
Id_1Me_1
12020-01-15
22021-12-31
Expected DS_r
Id_1Me_1Me_2
12020-01-152020-01-15
22021-12-312021-12-31

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Day month year order 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, date, "DD/MM/YYYY") on a String measure: the day first, then the month and the year, separated by /.

Manual:

Type Conversion and Formatting Mask: “The position of the digits in the mask denotes the position of the corresponding values”, and “Any other character can be used in the mask, meaning simply that it appears in the same position”.

Expected:

2018-04-05 and 2021-12-31: 05/04/2018 is the 5th of April.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, date, "DD/MM/YYYY")];
Input DS_1
Id_1Me_1
105/04/2018
231/12/2021
Expected DS_r
Id_1Me_1Me_2
105/04/20182018-04-05
231/12/20212021-12-31

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

String not matching mask 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, date, "DD/MM/YYYY") on a String measure whose value, 2018-04-05, is a date in the format of the conversion without a mask, not in the mask.

Manual:

Type conversion: “When performing a conversion from a string value, all leading and trailing blanks are removed from the input string value before performing the conversion. Then, if the input string or a part of it cannot be matched to the specified or default mask, an error is raised.”

Expected:

The error 2-1-5-3, “Impossible to cast {value} from type {type_1} to {type_2} using mask {mask}.”: 2018-04-05 has a - where the mask has a /. Without the mask, it would be the date 2018-04-05.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, date, "DD/MM/YYYY")];
Input DS_1
Id_1Me_1
12018-04-05

Expected error 2-1-5-3: Impossible to cast {value} from type {type_1} to {type_2} using mask {mask}.

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/error.json · example page ↗

cast(comp<string>, time_period) 🟢 · string → time_period

Quarter month and year 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, time_period) on a String measure, without a mask: a quarter, a month with a -, and a year.

Manual:

Type conversion, “To time_period”: four digits for the year, then “a - is consumed if present”, then “one of either H, Q, M or D is possibly consumed to determine the duration of the period; if neither of these are present, a time_period representing the entire determined year is returned”.

Expected:

2000Q1, 2000M03 from 2000-M03, and the year 2001A from 2001, the comparison taking 2001A and 2001 as the same period. The inputs have no blanks for the conversion to remove.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, time_period)];
Input DS_1
Id_1Me_1
12000Q1
22000-M03
32001
Expected DS_r
Id_1Me_1Me_2
12000Q12000Q1
22000-M032000M03
320012001A

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<string>, time_period, mask) 🟢 · string → time_period

Quarter mask 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, time_period, "YYYY\QQ") on a String measure: the mask of the page’s Example 9, cast ( "2000Q1", time_period, "YYYY\QQ" ), “The first quarter of year 2000”.

Manual:

Type Conversion and Formatting Mask: “The special characters and the special words, if prefixed by the reverse slash […] in the mask, appear in the same position in the time format”, so \Q is the letter Q, and Q the quarter.

Expected:

2000Q1, the first quarter of 2000, and 2001Q4. The conversion without a mask reads these strings the same way, so no value tells the two apart.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, time_period, "YYYY\QQ")];
Input DS_1
Id_1Me_1
12000Q1
22001Q4
Expected DS_r
Id_1Me_1Me_2
12000Q12000Q1
22001Q42001Q4

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Quarter after dash 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, time_period, "YYYY-Q") on a String measure: the mask of the page’s Example 9, cast ( "2000-1", time_period, "YYYY-Q" ): the quarter as a digit, with no letter Q.

Manual:

Type Conversion and Formatting Mask: the special characters include “Q quarter”; “The number of letters matches the number of digits”, and “Any other character can be used in the mask, meaning simply that it appears in the same position”.

Expected:

2000Q1, “The first quarter of year 2000”, and 2001Q4. Only the mask reads the digit as a quarter: without it, the conversion consumes the year and the -, finds none of H, Q, M or D, and raises an error for the digit left over, and vtlengine reads 2000-1 as the month 2000M1.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, time_period, "YYYY-Q")];
Input DS_1
Id_1Me_1
12000-1
22001-4
Expected DS_r
Id_1Me_1Me_2
12000-12000Q1
22001-42001Q4

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

Period indicator and number 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, time_period, "YYYYP{ppp}") on a String measure: the mask of a “Generic time period within the year”, with each period indicator.

Manual:

Type Conversion and Formatting Mask: “VTL Mask: YYYYP{ppp} where P is the period indicator and ppp three digits for the number of periods, in the values, the period indicator may assume one of the values of the duration scalar type listed below”: D, W, M, Q, S and A.

Expected:

The manual’s 2015Q4, 2015M12 and 2015D365, then 2015S2, 2015W12, and the year 2015A from 2015A1, A being the code of a year. Only the mask explains the last three: without it, the conversion reads the year, finds none of H, Q, M or D, and raises an error for the characters left over, and vtlengine reads 2015S2 and 2015W12 as they are and raises an error only for 2015A1.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, time_period, "YYYYP{ppp}")];
Input DS_1
Id_1Me_1
12015Q4
22015M12
32015D365
42015S2
52015W12
62015A1
Expected DS_r
Id_1Me_1Me_2
12015Q42015Q4
22015M122015M12
32015D3652015D365
42015S22015S2
52015W122015W12
62015A12015A

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<string>, duration) 🟢 · string → duration

One letter codes 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, duration) on a String measure, without a mask: the one-letter codes.

Manual:

Type conversion: “To duration: If the input string starts with P, the entire string is consumed and parsed, according to the ISO-8601 standard for durations […]. Otherwise, one of A, S, Q, M, W or D is consumed, and a duration value is returned representing the duration respectively of a year, a half of a year, a quarter of a year, a month, a week and a day.”

Expected:

A year, a quarter and a day, written with the same codes: A, Q and D. The inputs have no blanks for the conversion to remove.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, duration)];
Input DS_1
Id_1Me_1
1A
2Q
3D
Expected DS_r
Id_1Me_1Me_2
1AA
2QQ
3DD

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<string>, duration, mask) 🟢 · string → duration

Period indicator mask 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, duration, "P") on a String measure: the one-character mask of a duration, with each of its codes.

Manual:

Type Conversion and Formatting Mask: “Non ISO representation of the duration in one character, whose possible codes are”: “D Day”, “W Week”, “M Month”, “Q Quarter”, “S Semester” and “A Year”, with “VTL Mask: P (period indicator)”.

Expected:

The durations A, M, D, W, Q and S. The conversion without a mask reads these codes the same way, so no value tells the two apart.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, duration, "P")];
Input DS_1
Id_1Me_1
1A
2M
3D
4W
5Q
6S
Expected DS_r
Id_1Me_1Me_2
1AA
2MM
3DD
4WW
5QQ
6SS

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗

cast(comp<string>, VD) 🟢 · string, value domain → string

Values in the domain 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, VD_1) on a String measure whose values are in VD_1, after the page’s Example 6, cast(GEO_STRING, GEO_AREA).

Manual:

Type conversion: “VTL allows any value of a basic scalar type to be implicitly converted into a value belonging to a value domain or value domain subset based on that basic scalar type (downcast)”, and scalarType is any “scalar type (see the section: Data type syntax)”, which a value domain is.

Expected:

VD_1 is a String value domain of A, B and C, so A and B are kept as they are, and Me_2 is defined on VD_1, of the basic type String.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, VD_1)];
Input DS_1
Id_1Me_1
1A
2B
Expected DS_r
Id_1Me_1Me_2
1AA
2BB

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · value_domains/VD_1.json · example page ↗

cast(comp<VD>, VD) 🟢 · any scalar, value domain → any type

Values in both domains 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(Me_1, VD_1) on a measure of the value domain VD_2, after the page’s Example 8, cast (GEO, GEO_AREA1).

Manual:

Type conversion: “Since an element of a value domain is implicitly upcast into its corresponding basic scalar type, and in turn that value can be implictly downcast into another value domain based on that scalar type (or one of its subsets), an implicit conversion between those two domains is straightforward.”

Expected:

Me_1 takes its values from VD_2, A and B (its type in the input structure), which are in VD_1, A, B and C, so they are kept; Me_1 stays defined on VD_2 and Me_2 is defined on VD_1, of the basic type String.

script.vtl
DS_r := DS_1[calc Me_2 := cast(Me_1, VD_1)];
Input DS_1
Id_1Me_1
1A
2B
Expected DS_r
Id_1Me_1Me_2
1AA
2BB

Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · value_domains/VD_1.json · value_domains/VD_2.json · example page ↗

cast(sc<string>, integer) 🟢 · string → integer

String of digits 🟢 pandas ✅ · DuckDB ✅
Tests:

cast(SC_1, integer) on a scalar, with SC_1 = 42, a String.

Manual:

Type conversion, whose op may be a scalar: “a sequence of digits is consumed to determine its absolute value”.

Expected:

SC_r = 42, an Integer.

script.vtl
SC_r := cast(SC_1, integer);
Input scalars
SC_1
42
Expected scalars

Name

Type

Value

SC_r

Integer

"42"

Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗