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

Function test_meta_nonempty_index

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

Source from the content-addressed store, hash-verified

284
285
286def test_meta_nonempty_index():
287 idx = pd.RangeIndex(1, name="foo")
288 res = meta_nonempty(idx)
289 assert type(res) is pd.RangeIndex
290 assert res.name == idx.name
291
292 idx = pd.Index([1], name="foo", dtype="int")
293 res = meta_nonempty(idx)
294 assert type(res) is type(idx)
295 assert res.dtype == np.int_
296 assert res.name == idx.name
297
298 idx = pd.Index(["a"], name="foo")
299 res = meta_nonempty(idx)
300 assert type(res) is pd.Index
301 assert res.name == idx.name
302
303 idx = pd.DatetimeIndex(["1970-01-01"], freq="D", tz="America/New_York", name="foo")
304 res = meta_nonempty(idx)
305 assert type(res) is pd.DatetimeIndex
306 assert res.tz == idx.tz
307 assert res.freq == idx.freq
308 assert res.name == idx.name
309
310 idx = pd.PeriodIndex(["1970-01-01"], freq="D", name="foo")
311 res = meta_nonempty(idx)
312 assert type(res) is pd.PeriodIndex
313 assert res.freq == idx.freq
314 assert res.name == idx.name
315
316 idx = pd.TimedeltaIndex([pd.Timedelta(1, "D")], freq="D", name="foo")
317 res = meta_nonempty(idx)
318 assert type(res) is pd.TimedeltaIndex
319 assert res.freq == idx.freq
320 assert res.name == idx.name
321
322 idx = pd.CategoricalIndex(["xyx"], ["xyx", "zzz"], ordered=True, name="foo")
323 res = meta_nonempty(idx)
324 assert type(res) is pd.CategoricalIndex
325 assert (res.categories == idx.categories).all()
326 assert res.ordered == idx.ordered
327 assert res.name == idx.name
328
329 idx = pd.CategoricalIndex([], [UNKNOWN_CATEGORIES], ordered=True, name="foo")
330 res = meta_nonempty(idx)
331 assert type(res) is pd.CategoricalIndex
332 assert res.ordered == idx.ordered
333 assert res.name == idx.name
334
335 levels = [pd.Index([1], name="a"), pd.Index([1.0], name="b")]
336 codes = [[0], [0]]
337 idx = pd.MultiIndex(levels=levels, names=["a", "b"], codes=codes)
338 res = meta_nonempty(idx)
339 assert type(res) is pd.MultiIndex
340 for idx1, idx2 in zip(idx.levels, res.levels):
341 assert type(idx1) is type(idx2)
342 assert idx1.name == idx2.name
343 assert res.names == idx.names

Callers

nothing calls this directly

Calls 1

allMethod · 0.45

Tested by

no test coverage detected