| 380 | |
| 381 | def test_schema_defaults_serialization(): |
| 382 | class InputSchema(pw.Schema): |
| 383 | boolean: bool = pw.column_definition(default_value=True, example=True) |
| 384 | integer: int = pw.column_definition(default_value=10, example=11) |
| 385 | double: float = pw.column_definition(default_value=-4.3, example=5.5) |
| 386 | string: str = pw.column_definition(default_value="abcd", example="efgh") |
| 387 | binary_data: bytes = pw.column_definition( |
| 388 | default_value=b"defgh", example=b"qwer" |
| 389 | ) |
| 390 | datetime_naive: pw.DateTimeNaive = pw.column_definition( |
| 391 | default_value=pw.DateTimeNaive(year=2025, month=1, day=17), |
| 392 | example=pw.DateTimeNaive(year=2025, month=1, day=18), |
| 393 | ) |
| 394 | datetime_utc_aware: pw.DateTimeUtc = pw.column_definition( |
| 395 | default_value=pw.DateTimeUtc(year=2025, month=1, day=17, tz=tz.UTC), |
| 396 | example=pw.DateTimeUtc(year=2025, month=1, day=19, tz=tz.UTC), |
| 397 | ) |
| 398 | duration: pw.Duration = pw.column_definition( |
| 399 | default_value=pw.Duration(days=5), example=pw.Duration(hours=10) |
| 400 | ) |
| 401 | ints: np.ndarray[None, int] = pw.column_definition( |
| 402 | default_value=np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]], dtype=int), |
| 403 | example=np.array([[[11, 22], [33, 44]], [[55, 66], [77, 88]]], dtype=int), |
| 404 | ) |
| 405 | floats: np.ndarray[None, float] = pw.column_definition( |
| 406 | default_value=np.array([[1.1, 2.2], [3.3, 4.4]], dtype=float), |
| 407 | example=np.array([[1.11, 2.22], [3.33, 4.44]], dtype=float), |
| 408 | ) |
| 409 | ints_flat: np.ndarray[None, int] = pw.column_definition( |
| 410 | default_value=np.array([9, 9, 9], dtype=int), |
| 411 | example=np.array([99, 99, 99], dtype=int), |
| 412 | ) |
| 413 | floats_flat: np.ndarray[None, float] = pw.column_definition( |
| 414 | default_value=np.array([1.1, 2.2, 3.3], dtype=float), |
| 415 | example=np.array([1.11, 2.22, 3.33], dtype=float), |
| 416 | ) |
| 417 | json_data: pw.Json = pw.column_definition( |
| 418 | default_value=pw.Json.parse('{"a": 15, "b": "hello"}'), |
| 419 | example=pw.Json.parse('{"c": "world"}'), |
| 420 | ) |
| 421 | tuple_data: tuple[bytes, bool] = pw.column_definition( |
| 422 | default_value=(b"world", True), |
| 423 | example=(b"World", False), |
| 424 | ) |
| 425 | list_data: list[str | None] = pw.column_definition( |
| 426 | default_value=("lorem", None, "ipsum"), |
| 427 | example=("Lorem", None, "Ipsum"), |
| 428 | ) |
| 429 | |
| 430 | serialized_schema = InputSchema.to_json_serializable_dict() |
| 431 | serialized_schema_json = json.dumps(serialized_schema, sort_keys=True) |