(tempdir)
| 404 | |
| 405 | |
| 406 | def test_store_decimal_as_integer(tempdir): |
| 407 | arr_decimal_1_9 = pa.array(list(map(Decimal, range(100))), |
| 408 | type=pa.decimal128(5, 2)) |
| 409 | arr_decimal_10_18 = pa.array(list(map(Decimal, range(100))), |
| 410 | type=pa.decimal128(16, 9)) |
| 411 | arr_decimal_gt18 = pa.array(list(map(Decimal, range(100))), |
| 412 | type=pa.decimal128(22, 2)) |
| 413 | arr_bool = pa.array([True, False] * 50) |
| 414 | data_decimal = [arr_decimal_1_9, arr_decimal_10_18, arr_decimal_gt18] |
| 415 | table = pa.Table.from_arrays(data_decimal, names=['a', 'b', 'c']) |
| 416 | |
| 417 | # Check with store_decimal_as_integer. |
| 418 | _check_roundtrip(table, |
| 419 | expected=table, |
| 420 | compression="gzip", |
| 421 | use_dictionary=False, |
| 422 | store_decimal_as_integer=True) |
| 423 | |
| 424 | # Check physical type in parquet schema |
| 425 | pqtestfile_path = os.path.join(tempdir, 'test.parquet') |
| 426 | pq.write_table(table, pqtestfile_path, |
| 427 | compression="gzip", |
| 428 | use_dictionary=False, |
| 429 | store_decimal_as_integer=True) |
| 430 | |
| 431 | pqtestfile = pq.ParquetFile(pqtestfile_path) |
| 432 | pqcol_decimal_1_9 = pqtestfile.schema.column(0) |
| 433 | pqcol_decimal_10_18 = pqtestfile.schema.column(1) |
| 434 | |
| 435 | assert pqcol_decimal_1_9.physical_type == 'INT32' |
| 436 | assert pqcol_decimal_10_18.physical_type == 'INT64' |
| 437 | |
| 438 | # Check with store_decimal_as_integer and delta-int encoding. |
| 439 | # DELTA_BINARY_PACKED requires parquet physical type to be INT64 or INT32 |
| 440 | _check_roundtrip(table, |
| 441 | expected=table, |
| 442 | compression="gzip", |
| 443 | use_dictionary=False, |
| 444 | store_decimal_as_integer=True, |
| 445 | column_encoding={ |
| 446 | 'a': 'DELTA_BINARY_PACKED', |
| 447 | 'b': 'DELTA_BINARY_PACKED' |
| 448 | }) |
| 449 | |
| 450 | # Check with mixed column types. |
| 451 | mixed_table = pa.Table.from_arrays( |
| 452 | [arr_decimal_1_9, arr_decimal_10_18, arr_decimal_gt18, arr_bool], |
| 453 | names=['a', 'b', 'c', 'd']) |
| 454 | _check_roundtrip(mixed_table, |
| 455 | expected=mixed_table, |
| 456 | use_dictionary=False, |
| 457 | store_decimal_as_integer=True) |
| 458 | |
| 459 | |
| 460 | def test_column_encoding(): |
nothing calls this directly
no test coverage detected