From e0d36ad90a03e4beec145746073154e57c0c5b91 Mon Sep 17 00:00:00 2001 From: Mateo Date: Fri, 27 Mar 2026 14:47:55 +0100 Subject: [PATCH 1/6] Add TimePeriodConfig for representation management and update TimePeriodHandler --- src/vtlengine/DataTypes/TimeHandling.py | 28 +++++++++++++++++-- src/vtlengine/DataTypes/__init__.py | 3 +- .../output/_time_period_representation.py | 5 +++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/vtlengine/DataTypes/TimeHandling.py b/src/vtlengine/DataTypes/TimeHandling.py index 204a449b2..5a0e74c8d 100644 --- a/src/vtlengine/DataTypes/TimeHandling.py +++ b/src/vtlengine/DataTypes/TimeHandling.py @@ -17,6 +17,18 @@ PERIOD_INDICATORS = ["A", "S", "Q", "M", "W", "D"] +class TimePeriodConfig: + _representation = "vtl" # Default representation + + @classmethod + def set_representation(cls, representation: str) -> None: + cls._representation = representation + + @classmethod + def get_representation(cls) -> str: + return cls._representation + + def date_to_period(date_value: date, period_indicator: str) -> Any: if period_indicator == "A": return TimePeriodHandler(f"{date_value.year}A") @@ -336,9 +348,9 @@ def change_indicator(self, new_indicator: str) -> None: ).period_number def vtl_representation(self) -> str: - """VTL representation: YYYY, YYYYSn, YYYYQn, YYYYMm, YYYYWw, YYYYDd (no hyphens).""" + """VTL representation: YYYYA, YYYYSn, YYYYQn, YYYYMm, YYYYWw, YYYYDd (no hyphens).""" if self.period_indicator == "A": - return f"{self.year}" + return f"{self.year}A" return f"{self.year}{self.period_indicator}{self.period_number}" def sdmx_gregorian_representation(self) -> str: @@ -387,6 +399,18 @@ def natural_representation(self) -> str: period_number_str = str(self.period_number) return f"{self.year}-{self.period_indicator}{period_number_str}" + def external_representation(self) -> str: + """Return the representation based on the configured TimePeriodConfig.""" + representation = TimePeriodConfig.get_representation() + if representation == "vtl": + return self.vtl_representation() + elif representation == "sdmx_gregorian": + return self.sdmx_gregorian_representation() + elif representation == "sdmx_reporting": + return self.sdmx_reporting_representation() + else: + return self.natural_representation() + class TimeIntervalHandler: _date1: str = "0" diff --git a/src/vtlengine/DataTypes/__init__.py b/src/vtlengine/DataTypes/__init__.py index 805cd6d2e..6e79c6562 100644 --- a/src/vtlengine/DataTypes/__init__.py +++ b/src/vtlengine/DataTypes/__init__.py @@ -144,12 +144,13 @@ def explicit_cast(cls, value: Any, from_type: Any) -> str: Boolean, String, Date, - TimePeriod, TimeInterval, }: return str(value) if from_type == Duration: return _SHORTCODE_TO_ISO.get(str(value), str(value)) + elif from_type == TimePeriod: + return TimePeriodHandler(str(value)).external_representation() raise RunTimeError( "2-1-5-1", diff --git a/src/vtlengine/files/output/_time_period_representation.py b/src/vtlengine/files/output/_time_period_representation.py index dd77f12b6..56fad1cbf 100644 --- a/src/vtlengine/files/output/_time_period_representation.py +++ b/src/vtlengine/files/output/_time_period_representation.py @@ -2,7 +2,7 @@ from typing import Union from vtlengine.DataTypes import TimePeriod -from vtlengine.DataTypes.TimeHandling import TimePeriodHandler +from vtlengine.DataTypes.TimeHandling import TimePeriodConfig, TimePeriodHandler from vtlengine.Exceptions import InputValidationException from vtlengine.Model import Dataset, Scalar @@ -21,6 +21,9 @@ def check_value(cls, value: str) -> "TimePeriodRepresentation": raise InputValidationException( code="0-1-1-15", value=value, valid_options=valid_options ) + + TimePeriodConfig.set_representation(value) + return cls(value) From 61c9412dae84db889ca53aed8475392d6384e9f6 Mon Sep 17 00:00:00 2001 From: Mateo Date: Fri, 27 Mar 2026 14:48:17 +0100 Subject: [PATCH 2/6] Added related tests --- tests/TimePeriod/test_time_period_formats.py | 91 +++++++++++++++++++- 1 file changed, 88 insertions(+), 3 deletions(-) diff --git a/tests/TimePeriod/test_time_period_formats.py b/tests/TimePeriod/test_time_period_formats.py index 45ec34494..17eabff6a 100644 --- a/tests/TimePeriod/test_time_period_formats.py +++ b/tests/TimePeriod/test_time_period_formats.py @@ -14,6 +14,7 @@ import pandas as pd import pytest +from vtlengine import run from vtlengine.DataTypes import TimePeriod from vtlengine.DataTypes._time_checking import check_time_period from vtlengine.DataTypes.TimeHandling import TimePeriodHandler @@ -177,7 +178,7 @@ def test_check_time_period_all_formats_consistent(expected: str, inputs: list) - vtl_repr_params = [ - ("2020A", "2020", "annual"), + ("2020A", "2020A", "annual"), ("2020S1", "2020S1", "semester 1"), ("2020S2", "2020S2", "semester 2"), ("2020Q1", "2020Q1", "quarter 1"), @@ -311,7 +312,7 @@ def get_tp_scalar(value: Optional[str]) -> Scalar: format_dataset_params = [ # (internal_value, mode, expected_output, id) # VTL - ("2020A", TimePeriodRepresentation.VTL, "2020", "vtl annual"), + ("2020A", TimePeriodRepresentation.VTL, "2020A", "vtl annual"), ("2020-M01", TimePeriodRepresentation.VTL, "2020M1", "vtl month"), ("2020-Q3", TimePeriodRepresentation.VTL, "2020Q3", "vtl quarter"), ("2020-S2", TimePeriodRepresentation.VTL, "2020S2", "vtl semester"), @@ -410,5 +411,89 @@ def test_format_external_multiple_values() -> None: format_time_period_external_representation(ds, TimePeriodRepresentation.VTL) assert len(ds.data["Id_1"]) == 3 assert ds.data["Id_1"].equals( - pd.Series(["2020", "2020M6", "2020Q2"], name="Id_1", dtype="string[pyarrow]") + pd.Series(["2020A", "2020M6", "2020Q2"], name="Id_1", dtype="string[pyarrow]") ) + + +# GH-635: cast(TimePeriod, String) uses the configured external representation + + +def _run_cast_tp_to_string(tp_values: List[str], time_period_output_format: str) -> Dataset: + from vtlengine.DataTypes.TimeHandling import TimePeriodConfig + + original = TimePeriodConfig.get_representation() + script = "DS_r <- DS_1[calc Me_2 := cast(Me_1, string)];" + data_structures = { + "datasets": [ + { + "name": "DS_1", + "DataStructure": [ + {"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": False}, + {"name": "Me_1", "type": "Time_Period", "role": "Measure", "nullable": True}, + ], + } + ] + } + data_df = pd.DataFrame({"Id_1": list(range(1, len(tp_values) + 1)), "Me_1": tp_values}) + try: + result = run( + script=script, + data_structures=data_structures, + datapoints={"DS_1": data_df}, + time_period_output_format=time_period_output_format, + ) + return result["DS_r"] + finally: + TimePeriodConfig.set_representation(original) + + +gh_635_params = [ + pytest.param( + ["2020", "2021", "2022"], + "natural", + ["2020", "2021", "2022"], + id="GH_635_1-annual_natural", + ), + pytest.param( + ["2020", "2021", "2022"], + "vtl", + ["2020A", "2021A", "2022A"], + id="GH_635_2-annual_vtl", + ), + pytest.param( + ["2020M1", "2020M6", "2020M12"], + "natural", + ["2020-01", "2020-06", "2020-12"], + id="GH_635_3-monthly_natural", + ), + pytest.param( + ["2020M1", "2020M6", "2020M12"], + "vtl", + ["2020M1", "2020M6", "2020M12"], + id="GH_635_4-monthly_vtl", + ), + pytest.param( + ["2020Q1", "2020Q4"], + "sdmx_reporting", + ["2020-Q1", "2020-Q4"], + id="GH_635_5-quarterly_sdmx_reporting", + ), + pytest.param( + ["2020", "2020M6", "2020Q3"], + "natural", + ["2020", "2020-06", "2020-Q3"], + id="GH_635_6-mixed_natural", + ), + pytest.param( + ["2020", "2021"], + "sdmx_reporting", + ["2020-A1", "2021-A1"], + id="GH_635_7-annual_sdmx_reporting", + ), +] + + +@pytest.mark.parametrize("tp_values, output_format, expected", gh_635_params) +def test_GH_635(tp_values: List[str], output_format: str, expected: List[str]) -> None: + ds = _run_cast_tp_to_string(tp_values, output_format) + assert list(ds.data["Me_2"]) == expected From c74456c9518f6ea326e699f6ba02a11ee7a294d1 Mon Sep 17 00:00:00 2001 From: Mateo Date: Fri, 27 Mar 2026 14:48:32 +0100 Subject: [PATCH 3/6] Fixed related tests --- tests/Cast/test_cast.py | 2 +- tests/DateTime/test_datetime.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/Cast/test_cast.py b/tests/Cast/test_cast.py index 205249ba4..597f22303 100644 --- a/tests/Cast/test_cast.py +++ b/tests/Cast/test_cast.py @@ -384,7 +384,7 @@ class TestCastTimePeriodToString: "input_val, expected", [ ("2024A", "2024A"), - ("2024-Q1", "2024-Q1"), + ("2024-Q1", "2024Q1"), ("2020A", "2020A"), ("2020Q1", "2020Q1"), (None, None), diff --git a/tests/DateTime/test_datetime.py b/tests/DateTime/test_datetime.py index 24bb3c722..b158f4671 100644 --- a/tests/DateTime/test_datetime.py +++ b/tests/DateTime/test_datetime.py @@ -350,7 +350,7 @@ def _to_pylist(series: pd.Series) -> List[Any]: # type: ignore[type-arg] ["2010A", "2012A", "2013A", "2011A", "2012A", "2014A"], [10, 30, 40, 50, 60, 80], ["A", "A", "A", "A", "B", "B", "B", "B"], - ["2010", "2011", "2012", "2013", "2011", "2012", "2013", "2014"], + ["2010A", "2011A", "2012A", "2013A", "2011A", "2012A", "2013A", "2014A"], [10, None, 30, 40, 50, 60, None, 80], id="annual_single", ), @@ -361,7 +361,7 @@ def _to_pylist(series: pd.Series) -> List[Any]: # type: ignore[type-arg] ["2010A", "2012A", "2013A", "2011A", "2012A", "2014A"], [10, 30, 40, 50, 60, 80], ["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"], - ["2010", "2011", "2012", "2013", "2014", "2010", "2011", "2012", "2013", "2014"], + ["2010A", "2011A", "2012A", "2013A", "2014A", "2010A", "2011A", "2012A", "2013A", "2014A"], [10, None, 30, 40, None, None, 50, 60, None, 80], id="annual_all", ), @@ -373,15 +373,15 @@ def _to_pylist(series: pd.Series) -> List[Any]: # type: ignore[type-arg] [1, 3, 10, 20, 40, 60], ["A", "A", "A", "A", "A", "A", "A", "A", "A"], [ - "2010", + "2010A", "2010Q1", "2010Q2", "2010Q3", "2010Q4", - "2011", + "2011A", "2011Q1", "2011Q2", - "2012", + "2012A", ], [1, 10, 20, None, 40, None, None, 60, 3], id="mixed_annual_quarterly_single", @@ -394,17 +394,17 @@ def _to_pylist(series: pd.Series) -> List[Any]: # type: ignore[type-arg] [1, 3, 10, 20, 40, 60], ["A"] * 15, [ - "2010", + "2010A", "2010Q1", "2010Q2", "2010Q3", "2010Q4", - "2011", + "2011A", "2011Q1", "2011Q2", "2011Q3", "2011Q4", - "2012", + "2012A", "2012Q1", "2012Q2", "2012Q3", From 7985687676bd6fcb7e2b4798d8a3a160513ce435 Mon Sep 17 00:00:00 2001 From: Mateo Date: Fri, 27 Mar 2026 15:11:42 +0100 Subject: [PATCH 4/6] Minor fix --- src/vtlengine/DataTypes/TimeHandling.py | 4 +-- tests/Cast/test_cast.py | 4 +-- tests/DateTime/test_datetime.py | 16 +++++------ .../data/DataSet/output/GL_563_1-1.csv | 28 +++++++++---------- .../data/DataSet/output/GL_563_1-2.csv | 28 +++++++++---------- tests/TimePeriod/test_time_period_formats.py | 8 +++--- 6 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/vtlengine/DataTypes/TimeHandling.py b/src/vtlengine/DataTypes/TimeHandling.py index 5a0e74c8d..b46934cdb 100644 --- a/src/vtlengine/DataTypes/TimeHandling.py +++ b/src/vtlengine/DataTypes/TimeHandling.py @@ -348,9 +348,9 @@ def change_indicator(self, new_indicator: str) -> None: ).period_number def vtl_representation(self) -> str: - """VTL representation: YYYYA, YYYYSn, YYYYQn, YYYYMm, YYYYWw, YYYYDd (no hyphens).""" + """VTL representation: YYYY, YYYYSn, YYYYQn, YYYYMm, YYYYWw, YYYYDd (no hyphens).""" if self.period_indicator == "A": - return f"{self.year}A" + return f"{self.year}" return f"{self.year}{self.period_indicator}{self.period_number}" def sdmx_gregorian_representation(self) -> str: diff --git a/tests/Cast/test_cast.py b/tests/Cast/test_cast.py index 597f22303..9633f60a3 100644 --- a/tests/Cast/test_cast.py +++ b/tests/Cast/test_cast.py @@ -383,9 +383,9 @@ class TestCastTimePeriodToString: @pytest.mark.parametrize( "input_val, expected", [ - ("2024A", "2024A"), + ("2024A", "2024"), ("2024-Q1", "2024Q1"), - ("2020A", "2020A"), + ("2020A", "2020"), ("2020Q1", "2020Q1"), (None, None), ], diff --git a/tests/DateTime/test_datetime.py b/tests/DateTime/test_datetime.py index b158f4671..24bb3c722 100644 --- a/tests/DateTime/test_datetime.py +++ b/tests/DateTime/test_datetime.py @@ -350,7 +350,7 @@ def _to_pylist(series: pd.Series) -> List[Any]: # type: ignore[type-arg] ["2010A", "2012A", "2013A", "2011A", "2012A", "2014A"], [10, 30, 40, 50, 60, 80], ["A", "A", "A", "A", "B", "B", "B", "B"], - ["2010A", "2011A", "2012A", "2013A", "2011A", "2012A", "2013A", "2014A"], + ["2010", "2011", "2012", "2013", "2011", "2012", "2013", "2014"], [10, None, 30, 40, 50, 60, None, 80], id="annual_single", ), @@ -361,7 +361,7 @@ def _to_pylist(series: pd.Series) -> List[Any]: # type: ignore[type-arg] ["2010A", "2012A", "2013A", "2011A", "2012A", "2014A"], [10, 30, 40, 50, 60, 80], ["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"], - ["2010A", "2011A", "2012A", "2013A", "2014A", "2010A", "2011A", "2012A", "2013A", "2014A"], + ["2010", "2011", "2012", "2013", "2014", "2010", "2011", "2012", "2013", "2014"], [10, None, 30, 40, None, None, 50, 60, None, 80], id="annual_all", ), @@ -373,15 +373,15 @@ def _to_pylist(series: pd.Series) -> List[Any]: # type: ignore[type-arg] [1, 3, 10, 20, 40, 60], ["A", "A", "A", "A", "A", "A", "A", "A", "A"], [ - "2010A", + "2010", "2010Q1", "2010Q2", "2010Q3", "2010Q4", - "2011A", + "2011", "2011Q1", "2011Q2", - "2012A", + "2012", ], [1, 10, 20, None, 40, None, None, 60, 3], id="mixed_annual_quarterly_single", @@ -394,17 +394,17 @@ def _to_pylist(series: pd.Series) -> List[Any]: # type: ignore[type-arg] [1, 3, 10, 20, 40, 60], ["A"] * 15, [ - "2010A", + "2010", "2010Q1", "2010Q2", "2010Q3", "2010Q4", - "2011A", + "2011", "2011Q1", "2011Q2", "2011Q3", "2011Q4", - "2012A", + "2012", "2012Q1", "2012Q2", "2012Q3", diff --git a/tests/TimePeriod/data/DataSet/output/GL_563_1-1.csv b/tests/TimePeriod/data/DataSet/output/GL_563_1-1.csv index b9e5e78d8..bd4b3ea02 100644 --- a/tests/TimePeriod/data/DataSet/output/GL_563_1-1.csv +++ b/tests/TimePeriod/data/DataSet/output/GL_563_1-1.csv @@ -1,15 +1,15 @@ FREQ,MEASURE,REF_AREA,TIME_PERIOD,UNIT_MEASURE,year_id,OBS_VALUE,ADJUSTMENT,BASE_PER,DECIMALS,OBS_STATUS,UNIT_MULT -Q,HPI_YDH,HUN,2007-Q1,IX,2007A,128.791663747366,S,2015,1,A,0 -Q,HPI_YDH,HUN,2007-Q2,IX,2007A,135.068262557786,S,2015,1,A,0 -Q,HPI_YDH,HUN,2007-Q3,IX,2007A,137.007469129715,S,2015,1,A,0 -Q,HPI_YDH,HUN,2007-Q4,IX,2007A,133.095968661608,S,2015,1,A,0 -Q,HPI_YDH,HUN,2008-Q1,IX,2008A,133.03554880574,S,2015,1,A,0 -Q,HPI_YDH,HUN,2008-Q2,IX,2008A,134.223860470646,S,2015,1,A,0 -Q,HPI_YDH,HUN,2008-Q3,IX,2008A,133.560759222016,S,2015,1,A,0 -Q,HPI_YDH,HUN,2008-Q4,IX,2008A,126.58631498202,S,2015,1,A,0 -Q,HPI_YDH,HUN,2009-Q1,IX,2009A,129.175020241349,S,2015,1,A,0 -Q,HPI_YDH,HUN,2009-Q2,IX,2009A,128.069036228621,S,2015,1,A,0 -Q,HPI_YDH,HUN,2009-Q3,IX,2009A,120.538647006447,S,2015,1,A,0 -Q,HPI_YDH,HUN,2009-Q4,IX,2009A,122.981069897426,S,2015,1,A,0 -Q,HPI_YDH,HUN,2010-Q1,IX,2010A,120.008425982046,S,2015,1,A,0 -Q,HPI_YDH,HUN,2010-Q2,IX,2010A,117.718433849041,S,2015,1,A,0 +Q,HPI_YDH,HUN,2007-Q1,IX,2007,128.791663747366,S,2015,1,A,0 +Q,HPI_YDH,HUN,2007-Q2,IX,2007,135.068262557786,S,2015,1,A,0 +Q,HPI_YDH,HUN,2007-Q3,IX,2007,137.007469129715,S,2015,1,A,0 +Q,HPI_YDH,HUN,2007-Q4,IX,2007,133.095968661608,S,2015,1,A,0 +Q,HPI_YDH,HUN,2008-Q1,IX,2008,133.03554880574,S,2015,1,A,0 +Q,HPI_YDH,HUN,2008-Q2,IX,2008,134.223860470646,S,2015,1,A,0 +Q,HPI_YDH,HUN,2008-Q3,IX,2008,133.560759222016,S,2015,1,A,0 +Q,HPI_YDH,HUN,2008-Q4,IX,2008,126.58631498202,S,2015,1,A,0 +Q,HPI_YDH,HUN,2009-Q1,IX,2009,129.175020241349,S,2015,1,A,0 +Q,HPI_YDH,HUN,2009-Q2,IX,2009,128.069036228621,S,2015,1,A,0 +Q,HPI_YDH,HUN,2009-Q3,IX,2009,120.538647006447,S,2015,1,A,0 +Q,HPI_YDH,HUN,2009-Q4,IX,2009,122.981069897426,S,2015,1,A,0 +Q,HPI_YDH,HUN,2010-Q1,IX,2010,120.008425982046,S,2015,1,A,0 +Q,HPI_YDH,HUN,2010-Q2,IX,2010,117.718433849041,S,2015,1,A,0 diff --git a/tests/TimePeriod/data/DataSet/output/GL_563_1-2.csv b/tests/TimePeriod/data/DataSet/output/GL_563_1-2.csv index c4b8bca0b..8c14e1afd 100644 --- a/tests/TimePeriod/data/DataSet/output/GL_563_1-2.csv +++ b/tests/TimePeriod/data/DataSet/output/GL_563_1-2.csv @@ -1,15 +1,15 @@ FREQ,MEASURE,REF_AREA,TIME_PERIOD,UNIT_MEASURE,year_id,year_id2,OBS_VALUE,ADJUSTMENT,BASE_PER,DECIMALS,OBS_STATUS,UNIT_MULT -Q,HPI_YDH,HUN,2007-Q1,IX,2007A,2007A,128.791663747366,S,2015,1,A,0 -Q,HPI_YDH,HUN,2007-Q2,IX,2007A,2007A,135.068262557786,S,2015,1,A,0 -Q,HPI_YDH,HUN,2007-Q3,IX,2007A,2007A,137.007469129715,S,2015,1,A,0 -Q,HPI_YDH,HUN,2007-Q4,IX,2007A,2007A,133.095968661608,S,2015,1,A,0 -Q,HPI_YDH,HUN,2008-Q1,IX,2008A,2008A,133.03554880574,S,2015,1,A,0 -Q,HPI_YDH,HUN,2008-Q2,IX,2008A,2008A,134.223860470646,S,2015,1,A,0 -Q,HPI_YDH,HUN,2008-Q3,IX,2008A,2008A,133.560759222016,S,2015,1,A,0 -Q,HPI_YDH,HUN,2008-Q4,IX,2008A,2008A,126.58631498202,S,2015,1,A,0 -Q,HPI_YDH,HUN,2009-Q1,IX,2009A,2009A,129.175020241349,S,2015,1,A,0 -Q,HPI_YDH,HUN,2009-Q2,IX,2009A,2009A,128.069036228621,S,2015,1,A,0 -Q,HPI_YDH,HUN,2009-Q3,IX,2009A,2009A,120.538647006447,S,2015,1,A,0 -Q,HPI_YDH,HUN,2009-Q4,IX,2009A,2009A,122.981069897426,S,2015,1,A,0 -Q,HPI_YDH,HUN,2010-Q1,IX,2010A,2010A,120.008425982046,S,2015,1,A,0 -Q,HPI_YDH,HUN,2010-Q2,IX,2010A,2010A,117.718433849041,S,2015,1,A,0 +Q,HPI_YDH,HUN,2007-Q1,IX,2007,2007,128.791663747366,S,2015,1,A,0 +Q,HPI_YDH,HUN,2007-Q2,IX,2007,2007,135.068262557786,S,2015,1,A,0 +Q,HPI_YDH,HUN,2007-Q3,IX,2007,2007,137.007469129715,S,2015,1,A,0 +Q,HPI_YDH,HUN,2007-Q4,IX,2007,2007,133.095968661608,S,2015,1,A,0 +Q,HPI_YDH,HUN,2008-Q1,IX,2008,2008,133.03554880574,S,2015,1,A,0 +Q,HPI_YDH,HUN,2008-Q2,IX,2008,2008,134.223860470646,S,2015,1,A,0 +Q,HPI_YDH,HUN,2008-Q3,IX,2008,2008,133.560759222016,S,2015,1,A,0 +Q,HPI_YDH,HUN,2008-Q4,IX,2008,2008,126.58631498202,S,2015,1,A,0 +Q,HPI_YDH,HUN,2009-Q1,IX,2009,2009,129.175020241349,S,2015,1,A,0 +Q,HPI_YDH,HUN,2009-Q2,IX,2009,2009,128.069036228621,S,2015,1,A,0 +Q,HPI_YDH,HUN,2009-Q3,IX,2009,2009,120.538647006447,S,2015,1,A,0 +Q,HPI_YDH,HUN,2009-Q4,IX,2009,2009,122.981069897426,S,2015,1,A,0 +Q,HPI_YDH,HUN,2010-Q1,IX,2010,2010,120.008425982046,S,2015,1,A,0 +Q,HPI_YDH,HUN,2010-Q2,IX,2010,2010,117.718433849041,S,2015,1,A,0 diff --git a/tests/TimePeriod/test_time_period_formats.py b/tests/TimePeriod/test_time_period_formats.py index 17eabff6a..e230b7712 100644 --- a/tests/TimePeriod/test_time_period_formats.py +++ b/tests/TimePeriod/test_time_period_formats.py @@ -178,7 +178,7 @@ def test_check_time_period_all_formats_consistent(expected: str, inputs: list) - vtl_repr_params = [ - ("2020A", "2020A", "annual"), + ("2020A", "2020", "annual"), ("2020S1", "2020S1", "semester 1"), ("2020S2", "2020S2", "semester 2"), ("2020Q1", "2020Q1", "quarter 1"), @@ -312,7 +312,7 @@ def get_tp_scalar(value: Optional[str]) -> Scalar: format_dataset_params = [ # (internal_value, mode, expected_output, id) # VTL - ("2020A", TimePeriodRepresentation.VTL, "2020A", "vtl annual"), + ("2020A", TimePeriodRepresentation.VTL, "2020", "vtl annual"), ("2020-M01", TimePeriodRepresentation.VTL, "2020M1", "vtl month"), ("2020-Q3", TimePeriodRepresentation.VTL, "2020Q3", "vtl quarter"), ("2020-S2", TimePeriodRepresentation.VTL, "2020S2", "vtl semester"), @@ -411,7 +411,7 @@ def test_format_external_multiple_values() -> None: format_time_period_external_representation(ds, TimePeriodRepresentation.VTL) assert len(ds.data["Id_1"]) == 3 assert ds.data["Id_1"].equals( - pd.Series(["2020A", "2020M6", "2020Q2"], name="Id_1", dtype="string[pyarrow]") + pd.Series(["2020", "2020M6", "2020Q2"], name="Id_1", dtype="string[pyarrow]") ) @@ -457,7 +457,7 @@ def _run_cast_tp_to_string(tp_values: List[str], time_period_output_format: str) pytest.param( ["2020", "2021", "2022"], "vtl", - ["2020A", "2021A", "2022A"], + ["2020", "2021", "2022"], id="GH_635_2-annual_vtl", ), pytest.param( From 96337a229a4a6578c04eb133daac22794628c5b3 Mon Sep 17 00:00:00 2001 From: Mateo Date: Fri, 27 Mar 2026 15:27:50 +0100 Subject: [PATCH 5/6] Minor fix --- tests/conftest.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 000000000..31327df40 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,10 @@ +import pytest + +from vtlengine.DataTypes.TimeHandling import TimePeriodConfig + + +@pytest.fixture(autouse=True) +def _reset_time_period_config() -> None: # type: ignore[misc] + """Reset TimePeriodConfig to default after every test to prevent state leakage.""" + yield # type: ignore[misc] + TimePeriodConfig.set_representation("vtl") From 951010c0f85ab984f366edd35ab1fe4e0bb6b24d Mon Sep 17 00:00:00 2001 From: Mateo Date: Fri, 27 Mar 2026 15:34:17 +0100 Subject: [PATCH 6/6] Fixed tests references --- tests/Cast/data/Dataset/output/GL_563_1-1.csv | 28 +++++++++---------- tests/Cast/data/Dataset/output/GL_563_1-2.csv | 28 +++++++++---------- tests/conftest.py | 10 ------- 3 files changed, 28 insertions(+), 38 deletions(-) diff --git a/tests/Cast/data/Dataset/output/GL_563_1-1.csv b/tests/Cast/data/Dataset/output/GL_563_1-1.csv index b9e5e78d8..bd4b3ea02 100644 --- a/tests/Cast/data/Dataset/output/GL_563_1-1.csv +++ b/tests/Cast/data/Dataset/output/GL_563_1-1.csv @@ -1,15 +1,15 @@ FREQ,MEASURE,REF_AREA,TIME_PERIOD,UNIT_MEASURE,year_id,OBS_VALUE,ADJUSTMENT,BASE_PER,DECIMALS,OBS_STATUS,UNIT_MULT -Q,HPI_YDH,HUN,2007-Q1,IX,2007A,128.791663747366,S,2015,1,A,0 -Q,HPI_YDH,HUN,2007-Q2,IX,2007A,135.068262557786,S,2015,1,A,0 -Q,HPI_YDH,HUN,2007-Q3,IX,2007A,137.007469129715,S,2015,1,A,0 -Q,HPI_YDH,HUN,2007-Q4,IX,2007A,133.095968661608,S,2015,1,A,0 -Q,HPI_YDH,HUN,2008-Q1,IX,2008A,133.03554880574,S,2015,1,A,0 -Q,HPI_YDH,HUN,2008-Q2,IX,2008A,134.223860470646,S,2015,1,A,0 -Q,HPI_YDH,HUN,2008-Q3,IX,2008A,133.560759222016,S,2015,1,A,0 -Q,HPI_YDH,HUN,2008-Q4,IX,2008A,126.58631498202,S,2015,1,A,0 -Q,HPI_YDH,HUN,2009-Q1,IX,2009A,129.175020241349,S,2015,1,A,0 -Q,HPI_YDH,HUN,2009-Q2,IX,2009A,128.069036228621,S,2015,1,A,0 -Q,HPI_YDH,HUN,2009-Q3,IX,2009A,120.538647006447,S,2015,1,A,0 -Q,HPI_YDH,HUN,2009-Q4,IX,2009A,122.981069897426,S,2015,1,A,0 -Q,HPI_YDH,HUN,2010-Q1,IX,2010A,120.008425982046,S,2015,1,A,0 -Q,HPI_YDH,HUN,2010-Q2,IX,2010A,117.718433849041,S,2015,1,A,0 +Q,HPI_YDH,HUN,2007-Q1,IX,2007,128.791663747366,S,2015,1,A,0 +Q,HPI_YDH,HUN,2007-Q2,IX,2007,135.068262557786,S,2015,1,A,0 +Q,HPI_YDH,HUN,2007-Q3,IX,2007,137.007469129715,S,2015,1,A,0 +Q,HPI_YDH,HUN,2007-Q4,IX,2007,133.095968661608,S,2015,1,A,0 +Q,HPI_YDH,HUN,2008-Q1,IX,2008,133.03554880574,S,2015,1,A,0 +Q,HPI_YDH,HUN,2008-Q2,IX,2008,134.223860470646,S,2015,1,A,0 +Q,HPI_YDH,HUN,2008-Q3,IX,2008,133.560759222016,S,2015,1,A,0 +Q,HPI_YDH,HUN,2008-Q4,IX,2008,126.58631498202,S,2015,1,A,0 +Q,HPI_YDH,HUN,2009-Q1,IX,2009,129.175020241349,S,2015,1,A,0 +Q,HPI_YDH,HUN,2009-Q2,IX,2009,128.069036228621,S,2015,1,A,0 +Q,HPI_YDH,HUN,2009-Q3,IX,2009,120.538647006447,S,2015,1,A,0 +Q,HPI_YDH,HUN,2009-Q4,IX,2009,122.981069897426,S,2015,1,A,0 +Q,HPI_YDH,HUN,2010-Q1,IX,2010,120.008425982046,S,2015,1,A,0 +Q,HPI_YDH,HUN,2010-Q2,IX,2010,117.718433849041,S,2015,1,A,0 diff --git a/tests/Cast/data/Dataset/output/GL_563_1-2.csv b/tests/Cast/data/Dataset/output/GL_563_1-2.csv index c4b8bca0b..8c14e1afd 100644 --- a/tests/Cast/data/Dataset/output/GL_563_1-2.csv +++ b/tests/Cast/data/Dataset/output/GL_563_1-2.csv @@ -1,15 +1,15 @@ FREQ,MEASURE,REF_AREA,TIME_PERIOD,UNIT_MEASURE,year_id,year_id2,OBS_VALUE,ADJUSTMENT,BASE_PER,DECIMALS,OBS_STATUS,UNIT_MULT -Q,HPI_YDH,HUN,2007-Q1,IX,2007A,2007A,128.791663747366,S,2015,1,A,0 -Q,HPI_YDH,HUN,2007-Q2,IX,2007A,2007A,135.068262557786,S,2015,1,A,0 -Q,HPI_YDH,HUN,2007-Q3,IX,2007A,2007A,137.007469129715,S,2015,1,A,0 -Q,HPI_YDH,HUN,2007-Q4,IX,2007A,2007A,133.095968661608,S,2015,1,A,0 -Q,HPI_YDH,HUN,2008-Q1,IX,2008A,2008A,133.03554880574,S,2015,1,A,0 -Q,HPI_YDH,HUN,2008-Q2,IX,2008A,2008A,134.223860470646,S,2015,1,A,0 -Q,HPI_YDH,HUN,2008-Q3,IX,2008A,2008A,133.560759222016,S,2015,1,A,0 -Q,HPI_YDH,HUN,2008-Q4,IX,2008A,2008A,126.58631498202,S,2015,1,A,0 -Q,HPI_YDH,HUN,2009-Q1,IX,2009A,2009A,129.175020241349,S,2015,1,A,0 -Q,HPI_YDH,HUN,2009-Q2,IX,2009A,2009A,128.069036228621,S,2015,1,A,0 -Q,HPI_YDH,HUN,2009-Q3,IX,2009A,2009A,120.538647006447,S,2015,1,A,0 -Q,HPI_YDH,HUN,2009-Q4,IX,2009A,2009A,122.981069897426,S,2015,1,A,0 -Q,HPI_YDH,HUN,2010-Q1,IX,2010A,2010A,120.008425982046,S,2015,1,A,0 -Q,HPI_YDH,HUN,2010-Q2,IX,2010A,2010A,117.718433849041,S,2015,1,A,0 +Q,HPI_YDH,HUN,2007-Q1,IX,2007,2007,128.791663747366,S,2015,1,A,0 +Q,HPI_YDH,HUN,2007-Q2,IX,2007,2007,135.068262557786,S,2015,1,A,0 +Q,HPI_YDH,HUN,2007-Q3,IX,2007,2007,137.007469129715,S,2015,1,A,0 +Q,HPI_YDH,HUN,2007-Q4,IX,2007,2007,133.095968661608,S,2015,1,A,0 +Q,HPI_YDH,HUN,2008-Q1,IX,2008,2008,133.03554880574,S,2015,1,A,0 +Q,HPI_YDH,HUN,2008-Q2,IX,2008,2008,134.223860470646,S,2015,1,A,0 +Q,HPI_YDH,HUN,2008-Q3,IX,2008,2008,133.560759222016,S,2015,1,A,0 +Q,HPI_YDH,HUN,2008-Q4,IX,2008,2008,126.58631498202,S,2015,1,A,0 +Q,HPI_YDH,HUN,2009-Q1,IX,2009,2009,129.175020241349,S,2015,1,A,0 +Q,HPI_YDH,HUN,2009-Q2,IX,2009,2009,128.069036228621,S,2015,1,A,0 +Q,HPI_YDH,HUN,2009-Q3,IX,2009,2009,120.538647006447,S,2015,1,A,0 +Q,HPI_YDH,HUN,2009-Q4,IX,2009,2009,122.981069897426,S,2015,1,A,0 +Q,HPI_YDH,HUN,2010-Q1,IX,2010,2010,120.008425982046,S,2015,1,A,0 +Q,HPI_YDH,HUN,2010-Q2,IX,2010,2010,117.718433849041,S,2015,1,A,0 diff --git a/tests/conftest.py b/tests/conftest.py index 31327df40..e69de29bb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,10 +0,0 @@ -import pytest - -from vtlengine.DataTypes.TimeHandling import TimePeriodConfig - - -@pytest.fixture(autouse=True) -def _reset_time_period_config() -> None: # type: ignore[misc] - """Reset TimePeriodConfig to default after every test to prevent state leakage.""" - yield # type: ignore[misc] - TimePeriodConfig.set_representation("vtl")