Skip to content

Commit ab7c8fe

Browse files
reverting for 3.9 compatibility
1 parent a327162 commit ab7c8fe

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

pandasai/data_loader/semantic_layer_schema.py

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
22
from functools import partial
3-
from typing import Any, Dict, List
3+
from typing import Any, Dict, List, Optional, Union
44

55
import yaml
66
from pydantic import (
@@ -45,10 +45,10 @@ def __eq__(self, other):
4545

4646
class Column(BaseModel):
4747
name: str = Field(..., description="Name of the column.")
48-
type: str | None = Field(None, description="Data type of the column.")
49-
description: str | None = Field(None, description="Description of the column")
50-
expression: str | None = Field(None, description="Aggregation expression (avg, min, max, sum)")
51-
alias: str | None = Field(None, description="Alias for the column")
48+
type: Optional[str] = Field(None, description="Data type of the column.")
49+
description: Optional[str] = Field(None, description="Description of the column")
50+
expression: Optional[str] = Field(None, description="Aggregation expression (avg, min, max, sum)")
51+
alias: Optional[str] = Field(None, description="Alias for the column")
5252

5353
@field_validator("type")
5454
@classmethod
@@ -61,7 +61,7 @@ def is_column_type_supported(cls, type: str) -> str:
6161

6262
@field_validator("expression")
6363
@classmethod
64-
def is_expression_valid(cls, expr: str) -> str | None:
64+
def is_expression_valid(cls, expr: str) -> Optional[str]:
6565
if expr is None:
6666
return expr
6767
try:
@@ -72,83 +72,83 @@ def is_expression_valid(cls, expr: str) -> str | None:
7272

7373

7474
class Relation(BaseModel):
75-
name: str | None = Field(None, description="Name of the relationship.")
76-
description: str | None = Field(None, description="Description of the relationship.")
75+
name: Optional[str] = Field(None, description="Name of the relationship.")
76+
description: Optional[str] = Field(None, description="Description of the relationship.")
7777
from_: str = Field(..., alias="from", description="Source column for the relationship.")
7878
to: str = Field(..., description="Target column for the relationship.")
7979

8080

8181
class TransformationParams(BaseModel):
82-
column: str | None = Field(None, description="Column to transform")
83-
value: str | int | float | bool | None = Field(
82+
column: Optional[str] = Field(None, description="Column to transform")
83+
value: Optional[Union[str, int, float, bool]] = Field(
8484
None, description="Value for fill_na and other transformations"
8585
)
86-
mapping: Dict[str, str] | None = Field(
86+
mapping: Optional[Dict[str, str]] = Field(
8787
None, description="Mapping dictionary for map_values transformation"
8888
)
89-
format: str | None = Field(None, description="Format string for date formatting")
90-
decimals: int | None = Field(
89+
format: Optional[str] = Field(None, description="Format string for date formatting")
90+
decimals: Optional[int] = Field(
9191
None, description="Number of decimal places for rounding"
9292
)
93-
factor: int | float | None = Field(None, description="Scaling factor")
94-
to_tz: str | None = Field(None, description="Target timezone or format")
95-
from_tz: str | None = Field(None, description="From timezone or format")
96-
errors: str | None = Field(
93+
factor: Optional[Union[int, float]] = Field(None, description="Scaling factor")
94+
to_tz: Optional[str] = Field(None, description="Target timezone or format")
95+
from_tz: Optional[str] = Field(None, description="From timezone or format")
96+
errors: Optional[str] = Field(
9797
None, description="Error handling mode for numeric/datetime conversion"
9898
)
99-
old_value: Any | None = Field(
99+
old_value: Optional[Any] = Field(
100100
None, description="Old value for replace transformation"
101101
)
102-
new_value: Any | None = Field(
102+
new_value: Optional[Any] = Field(
103103
None, description="New value for replace transformation"
104104
)
105-
new_name: str | None = Field(
105+
new_name: Optional[str] = Field(
106106
None, description="New name for column in rename transformation"
107107
)
108-
pattern: str | None = Field(
108+
pattern: Optional[str] = Field(
109109
None, description="Pattern for extract transformation"
110110
)
111-
length: int | None = Field(
111+
length: Optional[int] = Field(
112112
None, description="Length for truncate transformation"
113113
)
114-
add_ellipsis: bool | None = Field(
114+
add_ellipsis: Optional[bool] = Field(
115115
True, description="Whether to add ellipsis in truncate"
116116
)
117-
width: int | None = Field(None, description="Width for pad transformation")
118-
side: str | None = Field("left", description="Side for pad transformation")
119-
pad_char: str | None = Field(" ", description="Character for pad transformation")
120-
lower: int | float | None = Field(None, description="Lower bound for clip")
121-
upper: int | float | None = Field(None, description="Upper bound for clip")
122-
bins: int | List[int | float] | None = Field(
117+
width: Optional[int] = Field(None, description="Width for pad transformation")
118+
side: Optional[str] = Field("left", description="Side for pad transformation")
119+
pad_char: Optional[str] = Field(" ", description="Character for pad transformation")
120+
lower: Optional[Union[int, float]] = Field(None, description="Lower bound for clip")
121+
upper: Optional[Union[int, float]] = Field(None, description="Upper bound for clip")
122+
bins: Optional[Union[int, List[Union[int, float]]]] = Field(
123123
None, description="Bins for binning"
124124
)
125-
labels: List[str] | None = Field(None, description="Labels for bins")
126-
drop_first: bool | None = Field(
125+
labels: Optional[List[str]] = Field(None, description="Labels for bins")
126+
drop_first: Optional[bool] = Field(
127127
True, description="Whether to drop first category in encoding"
128128
)
129-
drop_invalid: bool | None = Field(
129+
drop_invalid: Optional[bool] = Field(
130130
False, description="Whether to drop invalid values"
131131
)
132-
start_date: str | None = Field(
132+
start_date: Optional[str] = Field(
133133
None, description="Start date for date range validation"
134134
)
135-
end_date: str | None = Field(
135+
end_date: Optional[str] = Field(
136136
None, description="End date for date range validation"
137137
)
138-
country_code: str | None = Field(
138+
country_code: Optional[str] = Field(
139139
"+1", description="Country code for phone normalization"
140140
)
141-
columns: List[str] | None = Field(
141+
columns: Optional[List[str]] = Field(
142142
None, description="List of columns for multi-column operations"
143143
)
144-
keep: str | None = Field("first", description="Which duplicates to keep")
145-
ref_table: Any | None = Field(
144+
keep: Optional[str] = Field("first", description="Which duplicates to keep")
145+
ref_table: Optional[Any] = Field(
146146
None, description="Reference DataFrame for foreign key validation"
147147
)
148-
ref_column: str | None = Field(
148+
ref_column: Optional[str] = Field(
149149
None, description="Reference column for foreign key validation"
150150
)
151-
drop_negative: bool | None = Field(
151+
drop_negative: Optional[bool] = Field(
152152
False, description="Whether to drop negative values"
153153
)
154154

@@ -168,7 +168,7 @@ def validate_required_params(cls, values: dict) -> dict:
168168

169169
class Transformation(BaseModel):
170170
type: str = Field(..., description="Type of transformation to be applied.")
171-
params: TransformationParams | None = Field(
171+
params: Optional[TransformationParams] = Field(
172172
None, description="Parameters for the transformation."
173173
)
174174

@@ -191,11 +191,11 @@ def set_transform_type(cls, values: dict) -> dict:
191191

192192
class Source(BaseModel):
193193
type: str = Field(..., description="Type of the data source.")
194-
path: str | None = Field(None, description="Path of the local data source.")
195-
connection: SQLConnectionConfig | None = Field(
194+
path: Optional[str] = Field(None, description="Path of the local data source.")
195+
connection: Optional[SQLConnectionConfig] = Field(
196196
None, description="Connection object of the data source."
197197
)
198-
table: str | None = Field(None, description="Table of the data source.")
198+
table: Optional[str] = Field(None, description="Table of the data source.")
199199

200200
def is_compatible_source(self, source2: "Source"):
201201
"""
@@ -263,33 +263,33 @@ def is_format_supported(cls, format: str) -> str:
263263

264264
class SemanticLayerSchema(BaseModel):
265265
name: str = Field(..., description="Dataset name.")
266-
source: Source | None = Field(None, description="Data source for your dataset.")
267-
view: bool | None = Field(None, description="Whether table is a view")
268-
description: str | None = Field(
266+
source: Optional[Source] = Field(None, description="Data source for your dataset.")
267+
view: Optional[bool] = Field(None, description="Whether table is a view")
268+
description: Optional[str] = Field(
269269
None, description="Dataset’s contents and purpose description."
270270
)
271-
columns: List[Column] | None = Field(
271+
columns: Optional[List[Column]] = Field(
272272
None, description="Structure and metadata of your dataset’s columns"
273273
)
274-
relations: List[Relation] | None = Field(
274+
relations: Optional[List[Relation]] = Field(
275275
None, description="Relationships between columns and tables."
276276
)
277-
order_by: List[str] | None = Field(
277+
order_by: Optional[List[str]] = Field(
278278
None, description="Ordering criteria for the dataset."
279279
)
280-
limit: int | None = Field(
280+
limit: Optional[int] = Field(
281281
None, description="Maximum number of records to retrieve."
282282
)
283-
transformations: List[Transformation] | None = Field(
283+
transformations: Optional[List[Transformation]] = Field(
284284
None, description="List of transformations to apply to the data."
285285
)
286-
destination: Destination | None = Field(
286+
destination: Optional[Destination] = Field(
287287
None, description="Destination for saving the dataset."
288288
)
289-
update_frequency: str | None = Field(
289+
update_frequency: Optional[str] = Field(
290290
None, description="Frequency of dataset updates."
291291
)
292-
group_by: List[str] | None = Field(
292+
group_by: Optional[List[str]] = Field(
293293
None,
294294
description="List of columns to group by. Every non-aggregated column must be included in group_by.",
295295
)

0 commit comments

Comments
 (0)