diff --git a/py-tests/test_arrays.py b/py-tests/test_arrays.py index 23d9b48..bdc8f00 100644 --- a/py-tests/test_arrays.py +++ b/py-tests/test_arrays.py @@ -17,7 +17,8 @@ def test_arrays(self): """(1, Array['a', 'b'], Array[1, 2], Array['\\x01'::bytea, '\\x02'::bytea], Array[1.1, 2.2]), (2, NULL, NULL, NULL, NULL), (3, Array[NULL, 'a', NULL, 'b'], Array[]::int[], Array[NULL::bytea], Array[1.1, 'NaN'::numeric, 1000010]) - """ + """, + options=["--numeric-handling=decimal"] ) duckdb_table = duckdb.read_parquet(file).fetchall() self.assertEqual(duckdb_table[0], (1, ["a", "b"], [1, 2], [ b"\x01", b"\x02" ], [Decimal("1.10"), Decimal("2.20")])) @@ -63,7 +64,8 @@ def test_ranges(self): (1, '[1,2)', ARRAY['[1,2)'::int4range,'[2,3)'], ARRAY['[1.1,2.2)'::numrange,'[2.2,3.3)'], ARRAY['[2020-01-01 00:00:00,2020-01-02 00:00:00)'::tsrange,'[2020-01-02 00:00:00,2020-01-03 00:00:00)'::tsrange]), (2, NULL, NULL, NULL, NULL), (3, '(,2]', ARRAY[NULL::int4range, '(2,)', 'empty'], ARRAY['(1.1,)'::numrange,'(,)'], ARRAY[]::tsrange[]) - """ + """, + options=["--numeric-handling=decimal"] ) def r(low, up, low_inc=True, up_inc=False, is_empty=False): return {'lower': low, 'upper': up, 'lower_inclusive': low_inc, 'upper_inclusive': up_inc, 'is_empty': is_empty} diff --git a/py-tests/test_basic_types.py b/py-tests/test_basic_types.py index d7dfa8c..8a962be 100644 --- a/py-tests/test_basic_types.py +++ b/py-tests/test_basic_types.py @@ -102,11 +102,12 @@ def test_floats(self): self.assertEqual(list(polars_df["f32"].cast(str)), ['1.1', 'NaN', 'inf', '-inf', '-0.0']) self.assertEqual(list(polars_df["f64"].cast(str)), ['2.2', 'NaN', 'inf', '-inf', '-0.0']) - def test_numeric(self): + def test_decimal(self): file = wrappers.create_and_export( "numeric_types", "id", "id int, normal numeric(10, 5), high_precision numeric(140, 100)", - "(1, 1000.0001, 1.00000000000000000000000000000000000000000001), (2, 'NaN', 'NaN')" + "(1, 1000.0001, 1.00000000000000000000000000000000000000000001), (2, 'NaN', 'NaN')", + options=["--numeric-handling=decimal"] ) duckdb_table = duckdb.read_parquet(file).fetchall() self.assertEqual(duckdb_table, [ @@ -122,18 +123,18 @@ def test_numeric(self): # "high_precision": pl.Binary # }) - file2 = wrappers.run_export("numeric_types_higher_prec", "select * from numeric_types order by id", options=["--decimal-precision=76", "--decimal-scale=50"]) + file2 = wrappers.run_export("numeric_types_higher_prec", "select * from numeric_types order by id", options=["--decimal-precision=76", "--decimal-scale=50", "--numeric-handling=decimal"]) # only PyArrow supports precision=76 pd_df = pd.read_parquet(file2, engine="pyarrow") self.assertEqual(list(pd_df["normal"]), [Decimal('1000.000100000000000000'), None]) self.assertEqual(list(pd_df["high_precision"]), [Decimal('1.00000000000000000000000000000000000000000001'), None]) - def test_numeric_i32(self): + def test_decimal_i32(self): file = wrappers.create_and_export( "numeric_types", "id", "id int, normal numeric(10, 5), high_precision numeric(140, 100)", "(1, 1000.0001, 1.00000000000000000000000000000000000000000001), (2, 'NaN', 'NaN')", - options=["--decimal-precision=9", "--decimal-scale=4"] + options=["--decimal-precision=9", "--decimal-scale=4", "--numeric-handling=decimal"] ) duckdb_table = duckdb.read_parquet(file).fetchall() self.assertEqual(duckdb_table, [ @@ -141,12 +142,12 @@ def test_numeric_i32(self): (2, None, None ) ]) - def test_numeric_i64(self): + def test_decimal_i64(self): file = wrappers.create_and_export( "numeric_types", "id", "id int, normal numeric(10, 5), high_precision numeric(140, 100)", "(1, 1000.0001, 1.00000000000000000000000000000000000000000001), (2, 'NaN', 'NaN')", - options=["--decimal-precision=18", "--decimal-scale=9"] + options=["--decimal-precision=18", "--decimal-scale=9", "--numeric-handling=decimal"] ) duckdb_table = duckdb.read_parquet(file).fetchall() self.assertEqual(duckdb_table, [ @@ -158,7 +159,7 @@ def test_numeric_f64(self): "numeric_types", "id", "id int, normal numeric(10, 5), high_precision numeric(140, 100)", "(1, 1000.0001, 1.00000000000000000000000000000000000000000001), (2, 'NaN', 'NaN')", - options=["--numeric-handling=double"] + #options=["--numeric-handling=double"] ) duckdb_table = duckdb.read_parquet(file).fetchall() self.assertEqual(duckdb_table[0], (1, 1000.0001, 1))