vtlengine 1.4.0rc2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. vtlengine/API/_InternalApi.py +791 -0
  2. vtlengine/API/__init__.py +612 -0
  3. vtlengine/API/data/schema/external_routines_schema.json +34 -0
  4. vtlengine/API/data/schema/json_schema_2.1.json +116 -0
  5. vtlengine/API/data/schema/value_domain_schema.json +97 -0
  6. vtlengine/AST/ASTComment.py +57 -0
  7. vtlengine/AST/ASTConstructor.py +598 -0
  8. vtlengine/AST/ASTConstructorModules/Expr.py +1928 -0
  9. vtlengine/AST/ASTConstructorModules/ExprComponents.py +995 -0
  10. vtlengine/AST/ASTConstructorModules/Terminals.py +790 -0
  11. vtlengine/AST/ASTConstructorModules/__init__.py +50 -0
  12. vtlengine/AST/ASTDataExchange.py +10 -0
  13. vtlengine/AST/ASTEncoders.py +32 -0
  14. vtlengine/AST/ASTString.py +675 -0
  15. vtlengine/AST/ASTTemplate.py +558 -0
  16. vtlengine/AST/ASTVisitor.py +25 -0
  17. vtlengine/AST/DAG/__init__.py +479 -0
  18. vtlengine/AST/DAG/_words.py +10 -0
  19. vtlengine/AST/Grammar/Vtl.g4 +705 -0
  20. vtlengine/AST/Grammar/VtlTokens.g4 +409 -0
  21. vtlengine/AST/Grammar/__init__.py +0 -0
  22. vtlengine/AST/Grammar/lexer.py +2139 -0
  23. vtlengine/AST/Grammar/parser.py +16597 -0
  24. vtlengine/AST/Grammar/tokens.py +169 -0
  25. vtlengine/AST/VtlVisitor.py +824 -0
  26. vtlengine/AST/__init__.py +674 -0
  27. vtlengine/DataTypes/TimeHandling.py +562 -0
  28. vtlengine/DataTypes/__init__.py +863 -0
  29. vtlengine/DataTypes/_time_checking.py +135 -0
  30. vtlengine/Exceptions/__exception_file_generator.py +96 -0
  31. vtlengine/Exceptions/__init__.py +159 -0
  32. vtlengine/Exceptions/messages.py +1004 -0
  33. vtlengine/Interpreter/__init__.py +2048 -0
  34. vtlengine/Model/__init__.py +501 -0
  35. vtlengine/Operators/Aggregation.py +357 -0
  36. vtlengine/Operators/Analytic.py +455 -0
  37. vtlengine/Operators/Assignment.py +23 -0
  38. vtlengine/Operators/Boolean.py +106 -0
  39. vtlengine/Operators/CastOperator.py +451 -0
  40. vtlengine/Operators/Clause.py +366 -0
  41. vtlengine/Operators/Comparison.py +488 -0
  42. vtlengine/Operators/Conditional.py +495 -0
  43. vtlengine/Operators/General.py +191 -0
  44. vtlengine/Operators/HROperators.py +254 -0
  45. vtlengine/Operators/Join.py +447 -0
  46. vtlengine/Operators/Numeric.py +422 -0
  47. vtlengine/Operators/RoleSetter.py +77 -0
  48. vtlengine/Operators/Set.py +176 -0
  49. vtlengine/Operators/String.py +578 -0
  50. vtlengine/Operators/Time.py +1144 -0
  51. vtlengine/Operators/Validation.py +275 -0
  52. vtlengine/Operators/__init__.py +900 -0
  53. vtlengine/Utils/__Virtual_Assets.py +34 -0
  54. vtlengine/Utils/__init__.py +479 -0
  55. vtlengine/__extras_check.py +17 -0
  56. vtlengine/__init__.py +27 -0
  57. vtlengine/files/__init__.py +0 -0
  58. vtlengine/files/output/__init__.py +35 -0
  59. vtlengine/files/output/_time_period_representation.py +55 -0
  60. vtlengine/files/parser/__init__.py +240 -0
  61. vtlengine/files/parser/_rfc_dialect.py +22 -0
  62. vtlengine/py.typed +0 -0
  63. vtlengine-1.4.0rc2.dist-info/METADATA +89 -0
  64. vtlengine-1.4.0rc2.dist-info/RECORD +66 -0
  65. vtlengine-1.4.0rc2.dist-info/WHEEL +4 -0
  66. vtlengine-1.4.0rc2.dist-info/licenses/LICENSE.md +661 -0
@@ -0,0 +1,34 @@
1
+ from copy import copy
2
+
3
+
4
+ class VirtualCounter:
5
+ _instance = None
6
+ dataset_count: int = 0
7
+ component_count: int = 0
8
+
9
+ def __init__(self) -> None:
10
+ self.dataset_count = 0
11
+ self.component_count = 0
12
+
13
+ def __new__(cls): # type: ignore[no-untyped-def]
14
+ if cls._instance is None:
15
+ cls._instance = super(VirtualCounter, cls).__new__(cls)
16
+ cls._instance.reset()
17
+ return cls._instance
18
+
19
+ @classmethod
20
+ def reset(cls) -> None:
21
+ cls.dataset_count = 0
22
+ cls.component_count = 0
23
+
24
+ @classmethod
25
+ def _new_ds_name(cls) -> str:
26
+ cls.dataset_count += 1
27
+ name = f"__VDS_{copy(cls.dataset_count)}__"
28
+ return name
29
+
30
+ @classmethod
31
+ def _new_dc_name(cls) -> str:
32
+ cls.component_count += 1
33
+ name = f"__VDC_{copy(cls.component_count)}__"
34
+ return name
@@ -0,0 +1,479 @@
1
+ from typing import Any, Dict
2
+
3
+ from pysdmx.model.dataflow import Role
4
+
5
+ from vtlengine.AST.Grammar.tokens import (
6
+ ABS,
7
+ AGGREGATE,
8
+ AND,
9
+ APPLY,
10
+ AS,
11
+ ATTRIBUTE,
12
+ AVG,
13
+ CALC,
14
+ CEIL,
15
+ CHARSET_MATCH,
16
+ CONCAT,
17
+ COUNT,
18
+ CROSS_JOIN,
19
+ DATE_ADD,
20
+ DATEDIFF,
21
+ DAYOFMONTH,
22
+ DAYOFYEAR,
23
+ DAYTOMONTH,
24
+ DAYTOYEAR,
25
+ DIV,
26
+ DROP,
27
+ EQ,
28
+ EXP,
29
+ FILL_TIME_SERIES,
30
+ FILTER,
31
+ FIRST_VALUE,
32
+ FLOOR,
33
+ FLOW_TO_STOCK,
34
+ FULL_JOIN,
35
+ GT,
36
+ GTE,
37
+ IDENTIFIER,
38
+ IN,
39
+ INNER_JOIN,
40
+ INTERSECT,
41
+ ISNULL,
42
+ KEEP,
43
+ LAG,
44
+ LAST_VALUE,
45
+ LCASE,
46
+ LEAD,
47
+ LEFT_JOIN,
48
+ LEN,
49
+ LN,
50
+ LOG,
51
+ LT,
52
+ LTE,
53
+ LTRIM,
54
+ MAX,
55
+ MEASURE,
56
+ MEDIAN,
57
+ MEMBERSHIP,
58
+ MIN,
59
+ MINUS,
60
+ MOD,
61
+ MONTH,
62
+ MONTHTODAY,
63
+ MULT,
64
+ NEQ,
65
+ NOT,
66
+ NOT_IN,
67
+ NVL,
68
+ OR,
69
+ PERIOD_INDICATOR,
70
+ PIVOT,
71
+ PLUS,
72
+ POWER,
73
+ RANDOM,
74
+ RANK,
75
+ RATIO_TO_REPORT,
76
+ RENAME,
77
+ REPLACE,
78
+ ROUND,
79
+ RTRIM,
80
+ SETDIFF,
81
+ SQRT,
82
+ STDDEV_POP,
83
+ STDDEV_SAMP,
84
+ STOCK_TO_FLOW,
85
+ SUBSPACE,
86
+ SUBSTR,
87
+ SUM,
88
+ SYMDIFF,
89
+ TIMESHIFT,
90
+ TRIM,
91
+ TRUNC,
92
+ UCASE,
93
+ UNION,
94
+ UNPIVOT,
95
+ VAR_POP,
96
+ VAR_SAMP,
97
+ XOR,
98
+ YEAR,
99
+ YEARTODAY,
100
+ )
101
+ from vtlengine.Operators.Aggregation import (
102
+ Avg,
103
+ Count,
104
+ Max,
105
+ Median,
106
+ Min,
107
+ PopulationStandardDeviation,
108
+ PopulationVariance,
109
+ SampleStandardDeviation,
110
+ SampleVariance,
111
+ Sum,
112
+ )
113
+ from vtlengine.Operators.Analytic import (
114
+ Avg as AvgAnalytic,
115
+ )
116
+ from vtlengine.Operators.Analytic import (
117
+ Count as CountAnalytic,
118
+ )
119
+ from vtlengine.Operators.Analytic import (
120
+ FirstValue,
121
+ Lag,
122
+ LastValue,
123
+ Lead,
124
+ Rank,
125
+ RatioToReport,
126
+ )
127
+ from vtlengine.Operators.Analytic import (
128
+ Max as MaxAnalytic,
129
+ )
130
+ from vtlengine.Operators.Analytic import (
131
+ Median as MedianAnalytic,
132
+ )
133
+ from vtlengine.Operators.Analytic import (
134
+ Min as MinAnalytic,
135
+ )
136
+ from vtlengine.Operators.Analytic import (
137
+ PopulationStandardDeviation as PopulationStandardDeviationAnalytic,
138
+ )
139
+ from vtlengine.Operators.Analytic import (
140
+ PopulationVariance as PopulationVarianceAnalytic,
141
+ )
142
+ from vtlengine.Operators.Analytic import (
143
+ SampleStandardDeviation as SampleStandardDeviationAnalytic,
144
+ )
145
+ from vtlengine.Operators.Analytic import (
146
+ SampleVariance as SampleVarianceAnalytic,
147
+ )
148
+ from vtlengine.Operators.Analytic import (
149
+ Sum as SumAnalytic,
150
+ )
151
+ from vtlengine.Operators.Boolean import And, Not, Or, Xor
152
+ from vtlengine.Operators.Clause import (
153
+ Aggregate,
154
+ Calc,
155
+ Drop,
156
+ Filter,
157
+ Keep,
158
+ Pivot,
159
+ Rename,
160
+ Sub,
161
+ Unpivot,
162
+ )
163
+ from vtlengine.Operators.Comparison import (
164
+ Equal,
165
+ Greater,
166
+ GreaterEqual,
167
+ In,
168
+ IsNull,
169
+ Less,
170
+ LessEqual,
171
+ Match,
172
+ NotEqual,
173
+ NotIn,
174
+ )
175
+ from vtlengine.Operators.Conditional import Nvl
176
+ from vtlengine.Operators.General import Alias, Membership
177
+ from vtlengine.Operators.HROperators import (
178
+ HRBinMinus,
179
+ HRBinPlus,
180
+ HREqual,
181
+ HRGreater,
182
+ HRGreaterEqual,
183
+ HRLess,
184
+ HRLessEqual,
185
+ HRUnMinus,
186
+ HRUnPlus,
187
+ )
188
+ from vtlengine.Operators.Join import Apply, CrossJoin, FullJoin, InnerJoin, LeftJoin
189
+ from vtlengine.Operators.Numeric import (
190
+ AbsoluteValue,
191
+ BinMinus,
192
+ BinPlus,
193
+ Ceil,
194
+ Div,
195
+ Exponential,
196
+ Floor,
197
+ Logarithm,
198
+ Modulo,
199
+ Mult,
200
+ NaturalLogarithm,
201
+ Power,
202
+ Random,
203
+ Round,
204
+ SquareRoot,
205
+ Trunc,
206
+ UnMinus,
207
+ UnPlus,
208
+ )
209
+ from vtlengine.Operators.RoleSetter import Attribute, Identifier, Measure
210
+ from vtlengine.Operators.Set import Intersection, Setdiff, Symdiff, Union
211
+ from vtlengine.Operators.String import (
212
+ Concatenate,
213
+ Length,
214
+ Lower,
215
+ Ltrim,
216
+ Replace,
217
+ Rtrim,
218
+ Substr,
219
+ Trim,
220
+ Upper,
221
+ )
222
+ from vtlengine.Operators.Time import (
223
+ Date_Add,
224
+ Date_Diff,
225
+ Day_of_Month,
226
+ Day_of_Year,
227
+ Day_to_Month,
228
+ Day_to_Year,
229
+ Fill_time_series,
230
+ Flow_to_stock,
231
+ Month,
232
+ Month_to_Day,
233
+ Period_indicator,
234
+ Stock_to_flow,
235
+ Time_Shift,
236
+ Year,
237
+ Year_to_Day,
238
+ )
239
+
240
+ BINARY_MAPPING: Dict[Any, Any] = {
241
+ # General
242
+ MEMBERSHIP: Membership,
243
+ # Boolean
244
+ AND: And,
245
+ OR: Or,
246
+ XOR: Xor,
247
+ # Comparison
248
+ EQ: Equal,
249
+ NEQ: NotEqual,
250
+ GT: Greater,
251
+ GTE: GreaterEqual,
252
+ LT: Less,
253
+ LTE: LessEqual,
254
+ IN: In,
255
+ NOT_IN: NotIn,
256
+ # Conditional
257
+ NVL: Nvl,
258
+ # Numeric
259
+ PLUS: BinPlus,
260
+ MINUS: BinMinus,
261
+ MULT: Mult,
262
+ LOG: Logarithm,
263
+ MOD: Modulo,
264
+ POWER: Power,
265
+ DIV: Div,
266
+ RANDOM: Random,
267
+ # General
268
+ AS: Alias,
269
+ # String
270
+ CONCAT: Concatenate,
271
+ # Time
272
+ TIMESHIFT: Time_Shift,
273
+ CHARSET_MATCH: Match,
274
+ DATEDIFF: Date_Diff,
275
+ }
276
+
277
+ UNARY_MAPPING = {
278
+ # Boolean
279
+ NOT: Not,
280
+ # Comparison
281
+ # ISNULL: IsNull,
282
+ # Numeric
283
+ PLUS: UnPlus,
284
+ MINUS: UnMinus,
285
+ ABS: AbsoluteValue,
286
+ EXP: Exponential,
287
+ LN: NaturalLogarithm,
288
+ SQRT: SquareRoot,
289
+ CEIL: Ceil,
290
+ FLOOR: Floor,
291
+ ISNULL: IsNull,
292
+ # String
293
+ LEN: Length,
294
+ LCASE: Lower,
295
+ LTRIM: Ltrim,
296
+ RTRIM: Rtrim,
297
+ TRIM: Trim,
298
+ UCASE: Upper,
299
+ # Time
300
+ PERIOD_INDICATOR: Period_indicator,
301
+ FLOW_TO_STOCK: Flow_to_stock,
302
+ STOCK_TO_FLOW: Stock_to_flow,
303
+ YEAR: Year,
304
+ MONTH: Month,
305
+ DAYOFMONTH: Day_of_Month,
306
+ DAYOFYEAR: Day_of_Year,
307
+ DAYTOYEAR: Day_to_Year,
308
+ DAYTOMONTH: Day_to_Month,
309
+ YEARTODAY: Year_to_Day,
310
+ MONTHTODAY: Month_to_Day,
311
+ }
312
+
313
+ PARAMETRIC_MAPPING = {
314
+ # Numeric
315
+ ROUND: Round,
316
+ TRUNC: Trunc,
317
+ # String
318
+ SUBSTR: Substr,
319
+ REPLACE: Replace,
320
+ # Time
321
+ FILL_TIME_SERIES: Fill_time_series,
322
+ DATE_ADD: Date_Add,
323
+ }
324
+
325
+ ROLE_SETTER_MAPPING = {
326
+ IDENTIFIER: Identifier,
327
+ ATTRIBUTE: Attribute,
328
+ MEASURE: Measure,
329
+ }
330
+
331
+ REGULAR_AGGREGATION_MAPPING = {
332
+ CALC: Calc,
333
+ FILTER: Filter,
334
+ KEEP: Keep,
335
+ DROP: Drop,
336
+ RENAME: Rename,
337
+ PIVOT: Pivot,
338
+ UNPIVOT: Unpivot,
339
+ SUBSPACE: Sub,
340
+ AGGREGATE: Aggregate,
341
+ APPLY: Apply,
342
+ }
343
+
344
+ SET_MAPPING = {
345
+ UNION: Union,
346
+ INTERSECT: Intersection,
347
+ SYMDIFF: Symdiff,
348
+ SETDIFF: Setdiff,
349
+ }
350
+
351
+ AGGREGATION_MAPPING = {
352
+ MAX: Max,
353
+ MIN: Min,
354
+ SUM: Sum,
355
+ COUNT: Count,
356
+ AVG: Avg,
357
+ MEDIAN: Median,
358
+ STDDEV_POP: PopulationStandardDeviation,
359
+ STDDEV_SAMP: SampleStandardDeviation,
360
+ VAR_POP: PopulationVariance,
361
+ VAR_SAMP: SampleVariance,
362
+ }
363
+
364
+ ANALYTIC_MAPPING = {
365
+ MAX: MaxAnalytic,
366
+ MIN: MinAnalytic,
367
+ SUM: SumAnalytic,
368
+ COUNT: CountAnalytic,
369
+ AVG: AvgAnalytic,
370
+ MEDIAN: MedianAnalytic,
371
+ STDDEV_POP: PopulationStandardDeviationAnalytic,
372
+ STDDEV_SAMP: SampleStandardDeviationAnalytic,
373
+ VAR_POP: PopulationVarianceAnalytic,
374
+ VAR_SAMP: SampleVarianceAnalytic,
375
+ LAG: Lag,
376
+ LEAD: Lead,
377
+ FIRST_VALUE: FirstValue,
378
+ LAST_VALUE: LastValue,
379
+ RATIO_TO_REPORT: RatioToReport,
380
+ RANK: Rank,
381
+ }
382
+
383
+ THEN_ELSE = {"then": "T", "else": "E"}
384
+
385
+ JOIN_MAPPING = {
386
+ INNER_JOIN: InnerJoin,
387
+ LEFT_JOIN: LeftJoin,
388
+ FULL_JOIN: FullJoin,
389
+ CROSS_JOIN: CrossJoin,
390
+ }
391
+
392
+ HR_COMP_MAPPING = {
393
+ # Comparison
394
+ EQ: HREqual,
395
+ GT: HRGreater,
396
+ GTE: HRGreaterEqual,
397
+ LT: HRLess,
398
+ LTE: HRLessEqual,
399
+ }
400
+
401
+ HR_NUM_BINARY_MAPPING = {
402
+ # Numeric
403
+ PLUS: HRBinPlus,
404
+ MINUS: HRBinMinus,
405
+ }
406
+
407
+ HR_UNARY_MAPPING = {
408
+ # Numeric
409
+ PLUS: HRUnPlus,
410
+ MINUS: HRUnMinus,
411
+ }
412
+
413
+ HA_COMP_MAPPING = {
414
+ # Comparison
415
+ EQ: HREqual,
416
+ GT: HRGreater,
417
+ GTE: HRGreaterEqual,
418
+ LT: HRLess,
419
+ LTE: HRLessEqual,
420
+ }
421
+
422
+ HA_NUM_BINARY_MAPPING = {
423
+ # Numeric
424
+ PLUS: HRBinPlus,
425
+ MINUS: HRBinMinus,
426
+ }
427
+
428
+ HA_UNARY_MAPPING = {
429
+ # Numeric
430
+ PLUS: HRUnPlus,
431
+ MINUS: HRUnMinus,
432
+ }
433
+ VTL_DTYPES_MAPPING = {
434
+ "String": "String",
435
+ "Alpha": "String",
436
+ "AlphaNumeric": "String",
437
+ "Numeric": "String",
438
+ "BigInteger": "Integer",
439
+ "Integer": "Integer",
440
+ "Long": "Integer",
441
+ "Short": "Integer",
442
+ "Decimal": "Number",
443
+ "Float": "Number",
444
+ "Double": "Number",
445
+ "Boolean": "Boolean",
446
+ "URI": "String",
447
+ "Count": "Integer",
448
+ "InclusiveValueRange": "Number",
449
+ "ExclusiveValueRange": "Number",
450
+ "Incremental": "Number",
451
+ "ObservationalTimePeriod": "Time_Period",
452
+ "StandardTimePeriod": "Time_Period",
453
+ "BasicTimePeriod": "Date",
454
+ "GregorianTimePeriod": "Date",
455
+ "GregorianYear": "Date",
456
+ "GregorianYearMonth": "Date",
457
+ "GregorianMonth": "Date",
458
+ "GregorianDay": "Date",
459
+ "ReportingTimePeriod": "Time_Period",
460
+ "ReportingYear": "Time_Period",
461
+ "ReportingSemester": "Time_Period",
462
+ "ReportingTrimester": "Time_Period",
463
+ "ReportingQuarter": "Time_Period",
464
+ "ReportingMonth": "Time_Period",
465
+ "ReportingWeek": "Time_Period",
466
+ "ReportingDay": "Time_Period",
467
+ "DateTime": "Date",
468
+ "TimeRange": "Time",
469
+ "Month": "String",
470
+ "MonthDay": "String",
471
+ "Day": "String",
472
+ "Time": "String",
473
+ "Duration": "Duration",
474
+ }
475
+ VTL_ROLE_MAPPING = {
476
+ Role.DIMENSION: "Identifier",
477
+ Role.MEASURE: "Measure",
478
+ Role.ATTRIBUTE: "Attribute",
479
+ }
@@ -0,0 +1,17 @@
1
+ import importlib.util
2
+
3
+ EXTRAS_DOCS = "https://docs.vtlengine.meaningfuldata.eu/#installation"
4
+ ERROR_MESSAGE = (
5
+ "The '{extra_name}' extra is required to run {extra_desc}. "
6
+ "Please install it using 'pip install vtlengine[{extra_name}]' or "
7
+ "install all extras with 'pip install vtlengine[all]'. "
8
+ f"Check the documentation at: {EXTRAS_DOCS}"
9
+ )
10
+
11
+
12
+ def __check_s3_extra() -> None:
13
+ package_loc = importlib.util.find_spec("s3fs")
14
+ if package_loc is None:
15
+ raise ImportError(
16
+ ERROR_MESSAGE.format(extra_name="s3", extra_desc="over csv files using S3 URIs")
17
+ ) from None
vtlengine/__init__.py ADDED
@@ -0,0 +1,27 @@
1
+ from vtlengine.API import (
2
+ create_ast,
3
+ generate_sdmx,
4
+ prettify,
5
+ run,
6
+ run_sdmx,
7
+ semantic_analysis,
8
+ validate_dataset,
9
+ validate_external_routine,
10
+ validate_value_domain,
11
+ )
12
+ from vtlengine.AST.ASTComment import create_ast_with_comments
13
+
14
+ __all__ = [
15
+ "create_ast",
16
+ "create_ast_with_comments",
17
+ "semantic_analysis",
18
+ "run",
19
+ "generate_sdmx",
20
+ "run_sdmx",
21
+ "prettify",
22
+ "validate_dataset",
23
+ "validate_value_domain",
24
+ "validate_external_routine",
25
+ ]
26
+
27
+ __version__ = "1.4.0rc2"
File without changes
@@ -0,0 +1,35 @@
1
+ from pathlib import Path
2
+ from typing import Optional, Union
3
+
4
+ import pandas as pd
5
+
6
+ from vtlengine.__extras_check import __check_s3_extra
7
+ from vtlengine.files.output._time_period_representation import (
8
+ TimePeriodRepresentation,
9
+ format_time_period_external_representation,
10
+ )
11
+ from vtlengine.Model import Dataset
12
+
13
+
14
+ def save_datapoints(
15
+ time_period_representation: Optional[TimePeriodRepresentation],
16
+ dataset: Dataset,
17
+ output_path: Union[str, Path],
18
+ ) -> None:
19
+ if dataset.data is None:
20
+ dataset.data = pd.DataFrame()
21
+ if time_period_representation is not None:
22
+ format_time_period_external_representation(dataset, time_period_representation)
23
+ if isinstance(output_path, str):
24
+ __check_s3_extra()
25
+ if output_path.endswith("/"):
26
+ s3_file_output = output_path + f"{dataset.name}.csv"
27
+ else:
28
+ s3_file_output = output_path + f"/{dataset.name}.csv"
29
+ # start = time()
30
+ dataset.data.to_csv(s3_file_output, index=False)
31
+ # end = time()
32
+ # print(f"Dataset {dataset.name} saved to {s3_file_output}")
33
+ # print(f"Time to save data on s3 URI: {end - start}")
34
+ else:
35
+ dataset.data.to_csv(output_path / f"{dataset.name}.csv", index=False)
@@ -0,0 +1,55 @@
1
+ from enum import Enum
2
+ from typing import Union
3
+
4
+ from vtlengine.DataTypes import TimePeriod
5
+ from vtlengine.DataTypes.TimeHandling import TimePeriodHandler
6
+ from vtlengine.Model import Dataset, Scalar
7
+
8
+
9
+ class TimePeriodRepresentation(Enum):
10
+ # Time Period output format
11
+ SDMX_GREGORIAN = "sdmx_gregorian"
12
+ SDMX_REPORTING = "sdmx_reporting"
13
+ VTL = "vtl"
14
+
15
+ @classmethod
16
+ def check_value(cls, value: str) -> "TimePeriodRepresentation":
17
+ if value not in cls._value2member_map_:
18
+ raise Exception("Invalid Time Period Representation")
19
+ return cls(value)
20
+
21
+
22
+ def _format_vtl_representation(value: str) -> str:
23
+ return TimePeriodHandler(value).vtl_representation()
24
+
25
+
26
+ def format_time_period_external_representation(
27
+ dataset: Union[Dataset, Scalar], mode: TimePeriodRepresentation
28
+ ) -> None:
29
+ """
30
+ From SDMX time period representation to standard VTL representation (no hyphen).
31
+ 'A': 'nothing to do',
32
+ 'S': 'YYYY-Sx',
33
+ 'Q': 'YYYY-Qx',
34
+ 'M': 'YYYY-MM',
35
+ 'W': 'YYYY-Wxx',
36
+ 'D': 'YYYY-MM-DD'
37
+ """
38
+ if mode == TimePeriodRepresentation.SDMX_REPORTING:
39
+ return
40
+ elif mode == TimePeriodRepresentation.SDMX_GREGORIAN:
41
+ raise NotImplementedError
42
+
43
+ if isinstance(dataset, Scalar):
44
+ return
45
+
46
+ # VTL Representation
47
+ if dataset.data is None or len(dataset.data) == 0:
48
+ return
49
+ for comp in dataset.components.values():
50
+ if comp.data_type == TimePeriod:
51
+ dataset.data[comp.name] = dataset.data[comp.name].map(
52
+ _format_vtl_representation, na_action="ignore"
53
+ )
54
+
55
+ return