MCPcopy
hub / github.com/dask/dask / test_check_meta

Function test_check_meta

dask/dataframe/tests/test_utils_dataframe.py:404–486  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

402
403
404def test_check_meta():
405 df = pd.DataFrame(
406 {
407 "a": ["x", "y", "z"],
408 "b": [True, False, True],
409 "c": [1, 2.5, 3.5],
410 "d": [1, 2, 3],
411 "e": pd.Categorical(["x", "y", "z"]),
412 "f": pd.Series([1, 2, 3], dtype=np.uint64),
413 }
414 )
415 meta = df.iloc[:0]
416
417 # DataFrame metadata passthrough if correct
418 assert check_meta(df, meta) is df
419 # Series metadata passthrough if correct
420 e = df.e
421 assert check_meta(e, meta.e) is e
422 # numeric_equal means floats and ints are equivalent
423 d = df.d
424 f = df.f
425 assert check_meta(d, meta.d.astype("f8"), numeric_equal=True) is d
426 assert check_meta(f, meta.f.astype("f8"), numeric_equal=True) is f
427 assert check_meta(f, meta.f.astype("i8"), numeric_equal=True) is f
428
429 # Series metadata error
430 with pytest.raises(ValueError) as err:
431 check_meta(d, meta.d.astype("f8"), numeric_equal=False)
432 series = "pandas.core.series.Series" if not PANDAS_GE_300 else "pandas.Series"
433 assert str(err.value) == (
434 "Metadata mismatch found.\n"
435 "\n"
436 f"Partition type: `{series}`\n"
437 "+----------+---------+\n"
438 "| | dtype |\n"
439 "+----------+---------+\n"
440 "| Found | int64 |\n"
441 "| Expected | float64 |\n"
442 "+----------+---------+"
443 )
444
445 # DataFrame metadata error
446 meta2 = meta.astype({"a": "category", "d": "f8"})[["a", "b", "c", "d"]]
447 df2 = df[["a", "b", "d", "e"]]
448 with pytest.raises(ValueError) as err:
449 check_meta(df2, meta2, funcname="from_delayed")
450 frame = "pandas.core.frame.DataFrame" if not PANDAS_GE_300 else "pandas.DataFrame"
451
452 if PANDAS_GE_300:
453 string_type = "str " # space for alignment
454 else:
455 string_type = "object"
456
457 exp = textwrap.dedent(f"""\
458 Metadata mismatch found in `from_delayed`.
459
460 Partition type: `{frame}`
461 +--------+----------+----------+

Callers

nothing calls this directly

Calls 2

check_metaFunction · 0.90
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…