diff --git a/python/cudf/cudf/core/column/column.py b/python/cudf/cudf/core/column/column.py index 8b2c51dae90..66ae984ee81 100644 --- a/python/cudf/cudf/core/column/column.py +++ b/python/cudf/cudf/core/column/column.py @@ -518,7 +518,12 @@ def _scatter_by_slice( self._check_scatter_key_length(num_keys, value) - if step == 1: + if step == 1 and not isinstance( + self, (cudf.core.column.StructColumn, cudf.core.column.ListColumn) + ): + # NOTE: List & Struct dtypes aren't supported by both + # inplace & out-of-place fill. Hence we need to use scatter for + # these two types. if isinstance(value, cudf.core.scalar.Scalar): return self._fill(value, start, stop, inplace=True) else: diff --git a/python/cudf/cudf/core/scalar.py b/python/cudf/cudf/core/scalar.py index 1deb56963a7..36018425fc6 100644 --- a/python/cudf/cudf/core/scalar.py +++ b/python/cudf/cudf/core/scalar.py @@ -54,7 +54,11 @@ def __call__(self, value, dtype=None): # if an instance couldn't be found in the cache, # construct it and add to cache: obj = super().__call__(value, dtype=dtype) - self.__instances[cache_key] = obj + try: + self.__instances[cache_key] = obj + except TypeError: + # couldn't hash the arguments, don't cache: + return obj if len(self.__instances) > self.__maxsize: self.__instances.popitem(last=False) return obj diff --git a/python/cudf/cudf/tests/test_setitem.py b/python/cudf/cudf/tests/test_setitem.py index cb455ae831c..13b342e6c3b 100644 --- a/python/cudf/cudf/tests/test_setitem.py +++ b/python/cudf/cudf/tests/test_setitem.py @@ -242,3 +242,58 @@ def test_categorical_setitem_invalid(): "the categories first", ): gs[0] = 5 + + +def test_series_slice_setitem_list(): + actual = cudf.Series([[[1, 2], [2, 3]], [[3, 4]], [[4, 5]], [[6, 7]]]) + actual[slice(0, 3, 1)] = [[10, 11], [12, 23]] + expected = cudf.Series( + [ + [[10, 11], [12, 23]], + [[10, 11], [12, 23]], + [[10, 11], [12, 23]], + [[6, 7]], + ] + ) + assert_eq(actual, expected) + + actual = cudf.Series([[[1, 2], [2, 3]], [[3, 4]], [[4, 5]], [[6, 7]]]) + actual[0:3] = cudf.Scalar([[10, 11], [12, 23]]) + + assert_eq(actual, expected) + + +def test_series_slice_setitem_struct(): + actual = cudf.Series( + [ + {"a": {"b": 10}, "b": 11}, + {"a": {"b": 100}, "b": 5}, + {"a": {"b": 50}, "b": 2}, + {"a": {"b": 1000}, "b": 67}, + {"a": {"b": 4000}, "b": 1090}, + ] + ) + actual[slice(0, 3, 1)] = {"a": {"b": 5050}, "b": 101} + expected = cudf.Series( + [ + {"a": {"b": 5050}, "b": 101}, + {"a": {"b": 5050}, "b": 101}, + {"a": {"b": 5050}, "b": 101}, + {"a": {"b": 1000}, "b": 67}, + {"a": {"b": 4000}, "b": 1090}, + ] + ) + assert_eq(actual, expected) + + actual = cudf.Series( + [ + {"a": {"b": 10}, "b": 11}, + {"a": {"b": 100}, "b": 5}, + {"a": {"b": 50}, "b": 2}, + {"a": {"b": 1000}, "b": 67}, + {"a": {"b": 4000}, "b": 1090}, + ] + ) + actual[0:3] = cudf.Scalar({"a": {"b": 5050}, "b": 101}) + + assert_eq(actual, expected)