MCPcopy
hub / github.com/pandas-dev/pandas / test_create_table_index

Function test_create_table_index

pandas/tests/io/pytables/test_store.py:394–423  ·  view source on GitHub ↗
(temp_hdfstore)

Source from the content-addressed store, hash-verified

392
393
394def test_create_table_index(temp_hdfstore):
395 store = temp_hdfstore
396
397 def col(t, column):
398 return getattr(store.get_storer(t).table.cols, column)
399
400 # data columns
401 df = DataFrame(
402 np.random.default_rng(2).standard_normal((10, 4)),
403 columns=Index(list("ABCD")),
404 index=date_range("2000-01-01", periods=10, freq="B"),
405 )
406 df["string"] = "foo"
407 df["string2"] = "bar"
408 store.append("f", df, data_columns=["string", "string2"])
409 assert col("f", "index").is_indexed is True
410 assert col("f", "string").is_indexed is True
411 assert col("f", "string2").is_indexed is True
412
413 # specify index=columns
414 store.append("f2", df, index=["string"], data_columns=["string", "string2"])
415 assert col("f2", "index").is_indexed is False
416 assert col("f2", "string").is_indexed is True
417 assert col("f2", "string2").is_indexed is False
418
419 # try to index a non-table
420 store.put("f2", df)
421 msg = "cannot create table index on a Fixed format store"
422 with pytest.raises(TypeError, match=msg):
423 store.create_table_index("f2")
424
425
426def test_create_table_index_data_columns_argument(temp_hdfstore):

Callers

nothing calls this directly

Calls 8

DataFrameClass · 0.90
IndexClass · 0.90
date_rangeFunction · 0.90
putMethod · 0.80
create_table_indexMethod · 0.80
colFunction · 0.70
appendMethod · 0.45
raisesMethod · 0.45

Tested by

no test coverage detected