(db)
| 162 | |
| 163 | |
| 164 | def test_needs_rational(db): |
| 165 | import datetime |
| 166 | |
| 167 | now = datetime.datetime.now() |
| 168 | d = datetime.timedelta(seconds=1) |
| 169 | df = pd.DataFrame( |
| 170 | { |
| 171 | "a": list("ghjkl"), |
| 172 | "b": [now + i * d for i in range(5)], |
| 173 | "c": [True, True, False, True, True], |
| 174 | } |
| 175 | ) |
| 176 | df = pd.concat( |
| 177 | [ |
| 178 | df, |
| 179 | pd.DataFrame( |
| 180 | [ |
| 181 | {"a": "x", "b": now + d * 1000, "c": None}, |
| 182 | {"a": None, "b": now + d * 1001, "c": None}, |
| 183 | ] |
| 184 | ), |
| 185 | ] |
| 186 | ) |
| 187 | string_dtype = get_string_dtype() |
| 188 | with tmpfile() as f: |
| 189 | uri = f"sqlite:///{f}" |
| 190 | df.to_sql("test", uri, index=False, if_exists="replace") |
| 191 | |
| 192 | # one partition contains NULL |
| 193 | data = read_sql_table("test", uri, npartitions=2, index_col="b") |
| 194 | df2 = df.set_index("b") |
| 195 | assert_eq(data, df2.astype({"c": bool})) # bools are coerced |
| 196 | |
| 197 | # one partition contains NULL, but big enough head |
| 198 | data = read_sql_table("test", uri, npartitions=2, index_col="b", head_rows=12) |
| 199 | df2 = df.set_index("b") |
| 200 | assert_eq(data, df2) |
| 201 | |
| 202 | # empty partitions |
| 203 | data = read_sql_table("test", uri, npartitions=20, index_col="b") |
| 204 | part = data.get_partition(12).compute() |
| 205 | assert part.dtypes.tolist() == [string_dtype, bool] |
| 206 | assert part.empty |
| 207 | df2 = df.set_index("b") |
| 208 | assert_eq(data, df2.astype({"c": bool})) |
| 209 | |
| 210 | # explicit meta |
| 211 | data = read_sql_table("test", uri, npartitions=2, index_col="b", meta=df2[:0]) |
| 212 | part = data.get_partition(1).compute() |
| 213 | assert part.dtypes.tolist() == [string_dtype, string_dtype] |
| 214 | df2 = df.set_index("b") |
| 215 | assert_eq(data, df2, check_dtype=False) |
| 216 | |
| 217 | |
| 218 | def test_simple(db): |
nothing calls this directly
no test coverage detected
searching dependent graphs…