MCPcopy
hub / github.com/pydata/xarray / test_to_dask_dataframe_2D

Method test_to_dask_dataframe_2D

xarray/tests/test_dask.py:853–871  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

851 "which causes the `y` column to have a different type depending on whether pyarrow is installed"
852 )
853 def test_to_dask_dataframe_2D(self):
854 # Test if 2-D dataset is supplied
855 w = np.random.randn(2, 3)
856 ds = Dataset({"w": (("x", "y"), da.from_array(w, chunks=(1, 2)))})
857 ds["x"] = ("x", np.array([0, 1], np.int64))
858 ds["y"] = ("y", list("abc"))
859
860 # dask dataframes do not (yet) support multiindex,
861 # but when it does, this would be the expected index:
862 exp_index = pd.MultiIndex.from_arrays(
863 [[0, 0, 0, 1, 1, 1], ["a", "b", "c", "a", "b", "c"]], names=["x", "y"]
864 )
865 expected = pd.DataFrame({"w": w.reshape(-1)}, index=exp_index)
866 # so for now, reset the index
867 expected = expected.reset_index(drop=False)
868 actual = ds.to_dask_dataframe(set_index=False)
869
870 assert isinstance(actual, dd.DataFrame)
871 assert_frame_equal(actual.compute(), expected)
872
873 @pytest.mark.xfail(raises=NotImplementedError)
874 def test_to_dask_dataframe_2D_set_index(self):

Callers

nothing calls this directly

Calls 5

to_dask_dataframeMethod · 0.95
DatasetClass · 0.90
from_arrayMethod · 0.45
reset_indexMethod · 0.45
computeMethod · 0.45

Tested by

no test coverage detected