Data Types
This page documents the data types supported by vtlengine, covering input formats, internal representation, output formats, and type casting rules based on the VTL 2.2 specification.
See also
VTL Data Types — Full type system in the VTL 2.2 User Manual
Scalar type definitions — Detailed scalar type descriptions
Type conversion: cast — Cast operator reference
Type Conversion and Formatting Mask — Conversion rules and masks
Type Hierarchy
The VTL 2.2 specification defines a hierarchy of scalar types:
Scalar
├── String
├── Number
│ └── Integer (subtype of Number)
├── Time
│ ├── Date (subtype of Time)
│ └── Time_Period (subtype of Time)
├── Duration
└── Boolean
Note
In vtlengine, the VTL Time type is implemented as
TimeInterval, and Time_Period as TimePeriod.
The user-facing names remain Time and Time_Period.
Data Types Reference
Each type below describes how vtlengine handles input, storage, and output. For the formal VTL definitions, see External representations and literals.
String
Input (CSV) |
Any text value. Surrounding double quotes are stripped automatically. |
Input (DataFrame) |
Any value (all values pass validation). A native
Python |
Internal representation |
Python |
Output dtype |
|
Integer
Input (CSV) |
Whole numbers: |
Input (DataFrame) |
Values are cast via |
Internal representation |
Python |
Output dtype |
|
Integer is a subtype of Number — anywhere a Number is expected, an Integer is accepted automatically.
Number
Input (CSV) |
Decimal or integer numbers: |
Input (DataFrame) |
Values are cast via |
Internal representation |
IEEE 754 float64 in both execution engines: Python |
Output dtype |
|
Number arithmetic keeps 15 significant digits: every binary arithmetic result is rounded to OUTPUT_NUMBER_SIGNIFICANT_DIGITS significant digits by the same kernel in both execution engines, so results and CSV output are identical across engines.
Boolean
Input (CSV) |
|
Input (DataFrame) |
Same string values or native Python
|
Internal representation |
Python |
Output dtype |
|
Output (CSV) |
|
Date
Input (CSV) |
ISO 8601 date: |
Input (DataFrame) |
String values validated against the same ISO 8601 formats, or values pandas has already parsed into dates or datetimes, read on the same rule. |
Input (scalar value) |
A |
Internal representation |
Python |
Output format |
ISO 8601 with |
Output dtype |
|
dateadd and timeshift give a Date of the years 1000–9999
only, the years a Date is read in: a result out of them raises
2-1-19-10, in both execution engines.
timeshift and fill_time_series read the period of a series of
Dates from the days of its values: the day, the week, the month, the
quarter, the semester or the year. The shortest is the day, so two
values on one day, at different times of it, make a daily series, and
the periods are counted from the lower limit with its time of the
day: timeshift by one of 2020-01-15T10:30:00 and
2020-01-15T10:30:05 gives 2020-01-16T10:30:00 and
2020-01-16T10:30:05, and fill_time_series adds no Data Point
to them.
Date is a subtype of Time — anywhere a Time value is expected, a Date is accepted automatically.
Time_Period
Input (CSV/DataFrame) |
Multiple formats accepted (see tables below),
read without the whitespace around the value
(spaces, tabs and line breaks). The digits are
the ASCII ones. Year range: 1000–9999. A value
written in one of the formats that is no period
( |
Input (scalar value) |
A |
Internal representation |
Hyphenated string (e.g. |
Output dtype |
|
Accepted input formats:
Period |
Formats |
Examples |
|---|---|---|
Annual |
|
|
Semester |
|
|
Quarter |
|
|
Monthly |
|
|
Weekly |
|
|
Daily |
|
|
The operators >, <, >=, <= and between order the
periods of one period indicator; two periods of different indicators
raise 2-1-19-19. between(op, from, to) is
op >= from and op <= to, as the VTL 2.2 manual defines it, for
every type (the same types are accepted, and the values are ordered
as those two operators order them), except that it always compares
the operand with both bounds: it raises 2-1-19-19 for a bound of
another period indicator even when the other comparison is already
false, where the pair stops at a false first comparison. A null bound gives false where the other
comparison is false and null elsewhere.
The time operators count the periods of each year on its calendar: a
year has 52 or 53 ISO weeks and 365 or 366 days, so timeshift of
2020W53 by one period is 2021W1, and fill_time_series adds
2020W53 and 2020D366. A week stays in the year it is numbered
in, also when it ends in the next one: time_agg gives 2020Q4
and 2020 for 2020W53 (2020-12-28 to 2021-01-03). A result out
of the years 1000–9999 raises 2-1-19-10.
fill_time_series in all mode fills the periods of a
Time_Period to whole years, from the first period of the earliest
year to the last period of the latest one, also for a single Data
Point: 2020Q2 alone gives 2020Q1 to 2020Q4. A series of
Dates or of Time values of a single Data Point stays as it is, in
both execution engines: its period cannot be read from one value,
and the limits the manual gives, its earliest and latest values,
are that value.
Output formats (controlled by time_period_output_format
parameter):
Format |
Annual |
Semester |
Quarter |
Month |
Week |
Day |
|---|---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Not supported |
Not supported |
|
Not supported |
|
|
|
|
|
|
|
|
Writing a semester, a quarter or a week in "sdmx_gregorian"
raises 2-1-19-21, in both execution engines.
Time_Period is a subtype of Time — anywhere a Time value is expected, a Time_Period is accepted automatically.
Time (TimeInterval)
Input (CSV/DataFrame) |
ISO 8601 interval: |
Internal representation |
Python |
Output dtype |
|
Duration
Input (CSV/DataFrame) |
Single-letter period indicator: |
Internal representation |
Python |
Output dtype |
|
The operators >, <, >=, <= and between, max and
min (also as analytic functions) and the order by of an analytic
function order the Durations by their length, not by their text: D <
W < M < Q < S < A.
Null Handling
All VTL scalar types support null values (represented as
pd.NA / None), with one exception:
Identifiers cannot be null — loading data with null identifiers raises an error.
Measures and Attributes can be nullable (controlled by the
nullableflag in the data structure definition).
During operations, null propagates: any operation involving
a null operand typically produces a null result.
The Null type is compatible with all other types for
implicit promotion.
Type Casting
Implicit Casting (Automatic)
Implicit casts happen automatically when operators receive operands of different but compatible types. The engine resolves the common type using the type promotion rules defined in VTL 2.2: the common type of two operands is the type of one of them, to which the other one is implicitly cast. Two types that are only cast to a third one have no common type.
From / To |
String |
Number |
Integer |
Boolean |
Time |
Date |
Time_Period |
Duration |
|---|---|---|---|---|---|---|---|---|
String |
✅ |
— |
— |
— |
— |
— |
— |
— |
Number |
— |
✅ |
✅ |
— |
— |
— |
— |
— |
Integer |
— |
✅ |
✅ |
— |
— |
— |
— |
— |
Boolean |
✅ |
— |
— |
✅ |
— |
— |
— |
— |
Time |
— |
— |
— |
— |
✅ |
— |
— |
— |
Date |
— |
— |
— |
— |
✅ |
✅ |
— |
— |
Time_Period |
— |
— |
— |
— |
✅ |
— |
✅ |
— |
Duration |
— |
— |
— |
— |
— |
— |
— |
✅ |
Key rules:
Integer / Number: Both directions are implicit (Integer is a subtype of Number). The common type of an Integer and a Number is Number: the common Identifiers that the joins (whatever the order of their operands), the set operators, the binary operators,
exists_inandnvlmatch are matched as Number values and are Number in the result, so3.5does not match3; and a Component that the set operators give from an Integer and a Number is a Number.Date to Time: A Date is implicitly converted to a Time interval (
"2020-01-15"becomes"2020-01-15/2020-01-15").Time_Period to Time: A Time_Period is implicitly converted to a Time interval (
"2020-Q1"becomes"2020-01-01/2020-03-31"). So wherever an operator combines a Date or a Time_Period with a Time, the Date or the Time_Period is converted to a Time value: comparisons andin/not_incompare Time values;nvl,if,case, the set operators andunpivotgive a Time; and the common Identifiers that the joins (whatever the order of their operands), the binary operators,exists_inandnvlmatch are matched as Time values and are Time in the result.Date with Time_Period: Neither is implicitly converted to the other, so they have no common type, although both are converted to Time. An operator that receives both, such as
=,<,between,nvl,if,case,union, or a join, a binary operator,exists_inornvlon a Date and a Time_Period Identifier, raises a SemanticError, and the script mustcastone of them, as the Type conversion page of the VTL 2.2 reference manual asks for every conversion that is not implicit: for instancecast(Me_1, time_period) = Me_2.Boolean to String:
truebecomes"true",falsebecomes"false", as the VTL 2.2 reference manual defines it, in both execution engines. So a Boolean Identifier that those operators match with a String one is matched as its text, only"true"matchestrue, and the Identifier is a String in the result (a String is never converted to a Boolean, which onlycastdoes). Likewiseinandnot_incompare a String with a set of Booleans as text:"true" in {true}is true and"1" in {true}is false.Null to any type: Null is compatible with every type.
Explicit Casting (cast operator)
The cast operator converts values from one type to another:
/* Without mask */
DS_r <- cast(DS_1, integer);
/* With mask */
DS_r <- cast(DS_1, date, MASK);
Note
VTL type names in the cast operator are lowercase:
string, integer, number, boolean,
time, date, time_period, duration.
Supported conversions without mask
From / To |
String |
Number |
Integer |
Boolean |
Time |
Date |
Time_Period |
Duration |
|---|---|---|---|---|---|---|---|---|
String |
✅ |
✅ |
✅ |
— |
✅ |
✅ |
✅ |
✅ |
Number |
✅ |
✅ |
✅ |
✅ |
— |
— |
— |
— |
Integer |
✅ |
✅ |
✅ |
✅ |
— |
— |
— |
— |
Boolean |
✅ |
✅ |
✅ |
✅ |
— |
— |
— |
— |
Time |
✅ |
— |
— |
— |
✅ |
— |
— |
— |
Date |
✅ |
— |
— |
— |
— |
✅ |
✅ |
— |
Time_Period |
✅ |
— |
— |
— |
— |
— |
✅ |
— |
Duration |
✅ |
— |
— |
— |
— |
— |
— |
✅ |
Legend: ✅ = implemented.
Conversion details:
Number/Integer to Boolean:
0becomesfalse, any other value becomestrue.Boolean to Number/Integer:
truebecomes1(or1.0),falsebecomes0(or0.0).Boolean to String:
truebecomes"true",falsebecomes"false", as the VTL 2.2 reference manual defines it, in both execution engines. So a Boolean Identifier that those operators match with a String one is matched as its text, only"true"matchestrue, and the Identifier is a String in the result (a String is never converted to a Boolean, which onlycastdoes). Likewiseinandnot_incompare a String with a set of Booleans as text:"true" in {true}is true and"1" in {true}is false.String to Integer: Must be a valid integer string (rejects
"3.5").String to Date: The text is read as the loaders read a
Date(see the Date section above):"2020-1-15","20200115"and"2020-01-15T00:00:00"are2020-01-15, and a time other than midnight is kept. A text that is not aDateraises1-1-5-6for a literal and2-1-19-8for data.String to Time_Period: The text is read in any of the accepted input formats of a Time_Period (see the Time_Period section above), a date written without zeros too (
"2020-1-5"is2020D5), without the whitespace around it (" 2020Q1"is2020Q1), as the loaders read it. Astart/endtext is the period of its interval when that interval is a whole year, semester, quarter, month, week or day ("2020-01-01/2020-03-31"is2020Q1), as the VTL 2.2 reference manual defines it. Any other text raises1-1-5-6for a literal and2-1-5-1for data.Date to Time_Period: Converts to daily period (e.g.
"2020-01-15"becomes"2020D15"with the defaultvtloutput format).Time to Time_Period: A Time is the period of its interval when that interval is a whole year, semester, quarter, month, week or day of a year from 1000 (
2020-01-01/2020-03-31is2020Q1), as astart/endtext is. Any other Time raises2-1-5-1.
Supported conversions with mask
A mask gives the format of a String that is cast to, or from, a Number, an Integer, a Time, a Date, a Time_Period or a Duration. Both directions are supported, on both engines:
DS_r <- DS_1 [ calc Me_2 := cast(Me_1, date, "YYYY-MM-DD"),
Me_3 := cast(Me_4, string, "DD.DDD") ];
Type |
Example masks |
Example values |
|---|---|---|
Number |
|
|
Integer |
|
|
Date |
|
|
Time |
|
|
Time_Period |
|
|
Duration |
|
|
Number and Integer masks are made of D (one digit), * (any number of
digits), + (at least one digit) and, for a Number, a . or ,
separator between the integer and the decimal parts. A Number written with a
fixed number of decimals is rounded to them.
The masks of the time types are made of a digit for each letter of a time
unit: C century, Y year, S semester, Q quarter, M month,
W week, D day, h hour, m minute, s second, d decimal
of second, P period indicator and p number of periods. Braces enclose
the digits that may be left out ({M}M writes April as 4), a reverse
slash writes the next character as it is (\Q), and any other character
appears as it is. A day is within the month when the mask has one, within the
week when it has a week, and within the year otherwise; a Time_Period mask with
a day and a month, or a week, writes a daily period. A Time is two Date masks
separated by /.
A value that its mask does not describe raises RunTimeError 2-1-5-3, and
a mask that does not describe the type raises SemanticError 1-1-5-4. A
Date, a Time or a Time_Period read through a mask has the years 1000–9999, as
any other: a value of another year raises 2-1-5-3, and a literal of the
script, such as cast("0999-01-15", date, "YYYY-MM-DD"), SemanticError
1-1-5-6.
vtlengine does not support these parts of the VTL 2.2 masks, which raise
SemanticError 1-3-13:
the exponent
Eof a Number mask;the textual words
MONTH,DAYandAM/PM;the ISO 8601 composite durations, such as
P10Y2M12D: a Duration of vtlengine is one period indicator;a Time written with a duration, such as
YYYY-MM-DD/PY\YM\MDD\D.
Cast on datasets
When cast is applied to a Dataset, it must have exactly
one measure (monomeasure). The measure is renamed to a
generic name based on the target type:
Target type |
Renamed measure |
|---|---|
String |
|
Number |
|
Integer |
|
Boolean |
|
Time |
|
Time_Period |
|
Date |
|
Duration |
|
Note
When the source type can be implicitly promoted to the target type (e.g. Boolean to String, Integer to Number, or Number to Integer), the measure is not renamed.
Cast to a value domain
The target of cast can be the name of a value domain given in
value_domains (see Components Defined on a Value Domain):
DS_r <- DS_1 [calc Me_2 := cast(Me_1, VD_1)];
As the VTL manual describes, the cast converts the operand to the
basic type of the value domain, and then checks that the result is
a value of the value domain: cast(Me_1, VD_1) gives the values
of cast(cast(Me_1, <basic type of VD_1>), VD_1). The operand
can be of any type that casts to the basic type without a mask,
following the tables above, or on another value domain of such a
type; any other type raises 1-1-5-1. With a mask, the cast to
the basic type uses it. A value that is not a value of the value
domain raises 2-1-5-4 (1-1-5-6 for a literal).
The result is defined on the value domain. The Measure of a Data
Set is named as in a cast to the basic type: it keeps its name when
its type is implicitly promoted to the basic type, and takes the
generic name otherwise (int_var for a value domain of
integers). A scalar is defined on the value domain as well.