MCPcopy Create free account
hub / github.com/dask/dask / test_check_meta

Function test_check_meta

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

check_metaFunction · 0.90
astypeMethod · 0.45

Tested by

no test coverage detected