MCPcopy
hub / github.com/dask/dask / test_needs_rational

Function test_needs_rational

dask/dataframe/io/tests/test_sql.py:164–215  ·  view source on GitHub ↗
(db)

Source from the content-addressed store, hash-verified

162
163
164def 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
218def test_simple(db):

Callers

nothing calls this directly

Calls 9

set_indexMethod · 0.95
get_string_dtypeFunction · 0.90
tmpfileFunction · 0.90
read_sql_tableFunction · 0.90
assert_eqFunction · 0.90
to_sqlMethod · 0.80
get_partitionMethod · 0.80
astypeMethod · 0.45
computeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…