def test_set_index_as_property(): cdf = DataFrame() col1 = np.arange(10) col2 = np.arange(0, 20, 2) cdf["a"] = col1 cdf["b"] = col2 # Check set_index(Series) cdf.index = cdf["b"] assert_eq(cdf.index._values.to_array(), col2) with pytest.raises(ValueError): cdf.index = [list(range(10))] idx = pd.Index(np.arange(0, 1000, 100)) cdf.index = idx assert_eq(cdf.index.to_pandas(), idx) df = cdf.to_pandas() assert_eq(df.index, idx) head = cdf.head().to_pandas() assert_eq(head.index, idx[:5])
def test_set_index_as_property(): cdf = DataFrame() col1 = np.arange(10) col2 = np.arange(0, 20, 2) cdf["a"] = col1 cdf["b"] = col2 # Check set_index(Series) cdf.index = cdf["b"] np.testing.assert_array_equal(cdf.index.values, col2) with pytest.raises(ValueError): cdf.index = [list(range(10))] idx = np.arange(0, 1000, 100) cdf.index = idx np.testing.assert_array_equal(cdf.index.values, idx) df = cdf.to_pandas() np.testing.assert_array_equal(df.index.values, idx) head = cdf.head().to_pandas() np.testing.assert_array_equal(head.index.values, idx[:5])