|
1 | 1 | import re
|
2 | 2 | import sys
|
3 | 3 |
|
| 4 | +import pandas as pd |
4 | 5 | import pytest
|
| 6 | +from pandas._testing import assert_equal |
5 | 7 | from pueblo.testing.pandas import makeTimeDataFrame
|
6 | 8 | from sqlalchemy.exc import ProgrammingError
|
7 | 9 |
|
|
15 | 17 | df = makeTimeDataFrame(nper=INSERT_RECORDS, freq="S")
|
16 | 18 | df["time"] = df.index
|
17 | 19 |
|
| 20 | +float_double_data = { |
| 21 | + "col_1": [19556.88, 629414.27, 51570.0, 2933.52, 20338.98], |
| 22 | + "col_2": [ |
| 23 | + 15379.920000000002, |
| 24 | + 1107140.42, |
| 25 | + 8081.999999999999, |
| 26 | + 1570.0300000000002, |
| 27 | + 29468.539999999997, |
| 28 | + ], |
| 29 | +} |
| 30 | +float_double_df = pd.DataFrame.from_dict(float_double_data) |
| 31 | + |
18 | 32 |
|
19 | 33 | @pytest.mark.skipif(
|
20 | 34 | sys.version_info < (3, 8), reason="Feature not supported on Python 3.7 and earlier"
|
@@ -113,3 +127,33 @@ def test_table_kwargs_unknown(cratedb_service):
|
113 | 127 | "passed to [ALTER | CREATE] TABLE statement]"
|
114 | 128 | )
|
115 | 129 | )
|
| 130 | + |
| 131 | + |
| 132 | +@pytest.mark.skipif( |
| 133 | + sys.version_info < (3, 8), reason="Feature not supported on Python 3.7 and earlier" |
| 134 | +) |
| 135 | +@pytest.mark.skipif( |
| 136 | + SA_VERSION < SA_2_0, reason="Feature not supported on SQLAlchemy 1.4 and earlier" |
| 137 | +) |
| 138 | +def test_float_double(cratedb_service): |
| 139 | + """ |
| 140 | + Validate I/O with floating point numbers, specifically DOUBLE types. |
| 141 | +
|
| 142 | + Motto: Do not lose precision when DOUBLE is required. |
| 143 | + """ |
| 144 | + tablename = "pandas_double" |
| 145 | + engine = cratedb_service.database.engine |
| 146 | + float_double_df.to_sql( |
| 147 | + tablename, |
| 148 | + engine, |
| 149 | + if_exists="replace", |
| 150 | + index=False, |
| 151 | + ) |
| 152 | + cratedb_service.database.run_sql(f"REFRESH TABLE {tablename}") |
| 153 | + df_load = pd.read_sql_table(tablename, engine) |
| 154 | + |
| 155 | + before = float_double_df.sort_values(by="col_1", ignore_index=True) |
| 156 | + after = df_load.sort_values(by="col_1", ignore_index=True) |
| 157 | + |
| 158 | + pd.options.display.float_format = "{:.12f}".format |
| 159 | + assert_equal(before, after, check_exact=True) |
0 commit comments