def test_integer_index_apis(data, name, dtype): pindex = pd.Int64Index(data, dtype=dtype, name=name) # Int8Index gindex = cudf.Int8Index(data, dtype=dtype, name=name) assert_eq(pindex, gindex) assert gindex.dtype == np.dtype("int8") # Int16Index gindex = cudf.Int16Index(data, dtype=dtype, name=name) assert_eq(pindex, gindex) assert gindex.dtype == np.dtype("int16") # Int32Index gindex = cudf.Int32Index(data, dtype=dtype, name=name) assert_eq(pindex, gindex) assert gindex.dtype == np.dtype("int32") # Int64Index gindex = cudf.Int64Index(data, dtype=dtype, name=name) assert_eq(pindex, gindex) assert gindex.dtype == np.dtype("int64")
def test_index_copy_integer(name, dtype, deep=True): """Test for NumericIndex Copy Casts """ cidx = cudf.Int64Index([1, 2, 3]) pidx = cidx.to_pandas() pidx_copy = pidx.copy(name=name, deep=deep, dtype=dtype) cidx_copy = cidx.copy(name=name, deep=deep, dtype=dtype) assert_eq(pidx_copy, cidx_copy)
cidx = cudf.core.index.CategoricalIndex([1, 2, 3]) pidx = cidx.to_pandas() pidx_copy = pidx.copy(name=name, deep=deep, dtype=dtype) cidx_copy = cidx.copy(name=name, deep=deep, dtype=dtype) assert_eq(pidx_copy, cidx_copy) @pytest.mark.parametrize("deep", [True, False]) @pytest.mark.parametrize( "idx", [ cudf.DatetimeIndex(["2001", "2002", "2003"]), cudf.core.index.StringIndex(["a", "b", "c"]), cudf.Int64Index([1, 2, 3]), cudf.Float64Index([1.0, 2.0, 3.0]), cudf.CategoricalIndex([1, 2, 3]), cudf.CategoricalIndex(["a", "b", "c"]), ], ) def test_index_copy_deep(idx, deep): """Test if deep copy creates a new instance for device data. The general criterion is to compare `Buffer.ptr` between two data objects. Specifically for: - CategoricalIndex, this applies to both `.codes` and `.categories` - StringIndex, to every element in `._base_children` - Others, to `.base_data` No test is defined for RangeIndex. """ idx_copy = idx.copy(deep=deep)