Skip to content

Commit 5ef1cb4

Browse files
committed
Blacken the code
Signed-off-by: Arkadiusz Halicki <[email protected]>
1 parent 52fbe10 commit 5ef1cb4

File tree

3 files changed

+67
-94
lines changed

3 files changed

+67
-94
lines changed

pandera/api/polars/model.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def _build_columns( # pylint:disable=too-many-locals
5151
check_name = getattr(field, "check_name", None)
5252

5353
try:
54-
is_polars_dtype = inspect.isclass(
55-
annotation.raw_annotation
56-
) and issubclass(annotation.raw_annotation, pe.DataType)
54+
is_polars_dtype = inspect.isclass(annotation.raw_annotation) and issubclass(
55+
annotation.raw_annotation, pe.DataType
56+
)
5757
except TypeError:
5858
is_polars_dtype = False
5959

@@ -87,9 +87,7 @@ def _build_columns( # pylint:disable=too-many-locals
8787
or dtype
8888
):
8989
if check_name is False:
90-
raise SchemaInitError(
91-
f"'check_name' is not supported for {field_name}."
92-
)
90+
raise SchemaInitError(f"'check_name' is not supported for {field_name}.")
9391

9492
column_kwargs = (
9593
field.column_properties(
@@ -104,9 +102,7 @@ def _build_columns( # pylint:disable=too-many-locals
104102
columns[field_name] = Column(**column_kwargs)
105103

106104
else:
107-
raise SchemaInitError(
108-
f"Invalid annotation '{field_name}: {annotation.raw_annotation}'."
109-
)
105+
raise SchemaInitError(f"Invalid annotation '{field_name}: {annotation.raw_annotation}'.")
110106

111107
return columns
112108

@@ -149,9 +145,7 @@ def validate(
149145
inplace: bool = False,
150146
) -> Union[LazyFrame[Self], DataFrame[Self]]:
151147
"""%(validate_doc)s"""
152-
result = cls.to_schema().validate(
153-
check_obj, head, tail, sample, random_state, lazy, inplace
154-
)
148+
result = cls.to_schema().validate(check_obj, head, tail, sample, random_state, lazy, inplace)
155149
if isinstance(check_obj, pl.LazyFrame):
156150
return cast(LazyFrame[Self], result)
157151
else:
@@ -170,7 +164,7 @@ def to_json_schema(cls):
170164
FastAPI integration.
171165
"""
172166
schema = cls.to_schema()
173-
167+
174168
# Define a mapping from Polars data types to JSON schema types
175169
# This is more robust than string parsing
176170
POLARS_TO_JSON_TYPE_MAP = {
@@ -183,52 +177,48 @@ def to_json_schema(cls):
183177
pl.UInt16: "integer",
184178
pl.UInt32: "integer",
185179
pl.UInt64: "integer",
186-
187180
# Float types
188181
pl.Float32: "number",
189182
pl.Float64: "number",
190-
191183
# Boolean type
192184
pl.Boolean: "boolean",
193-
194185
# String types
195186
pl.Utf8: "string",
196187
pl.String: "string",
197-
198188
# Date/Time types
199189
pl.Date: "datetime",
200190
pl.Datetime: "datetime",
201191
pl.Time: "datetime",
202192
pl.Duration: "datetime",
203193
}
204-
194+
205195
def map_dtype_to_json_type(dtype):
206196
"""
207197
Map a Polars data type to a JSON schema type.
208-
198+
209199
Args:
210200
dtype: Polars data type
211-
201+
212202
Returns:
213203
str: JSON schema type string
214204
"""
215205
# First try the direct mapping
216206
if dtype.__class__ in POLARS_TO_JSON_TYPE_MAP:
217207
return POLARS_TO_JSON_TYPE_MAP[dtype.__class__]
218-
208+
219209
# Fallback to string representation check for edge cases
220210
dtype_str = str(dtype).lower()
221-
if 'float' in dtype_str:
211+
if "float" in dtype_str:
222212
return "number"
223-
elif 'int' in dtype_str:
213+
elif "int" in dtype_str:
224214
return "integer"
225-
elif 'bool' in dtype_str:
215+
elif "bool" in dtype_str:
226216
return "boolean"
227-
elif any(t in dtype_str for t in ['date', 'time', 'datetime']):
217+
elif any(t in dtype_str for t in ["date", "time", "datetime"]):
228218
return "datetime"
229219
else:
230220
return "string"
231-
221+
232222
properties = {}
233223
for col_name, col_schema in schema.dtypes.items():
234224
json_type = map_dtype_to_json_type(col_schema.type)

0 commit comments

Comments
 (0)