[FEA] Support string concatenation of a Series and something array-like into a Series
- Dominant language
- C++
- Stars
- 9.8k
- Forks
- 1.1k
- Avg merge
- 3d 6m
- Merged PRs (30d)
- 278
Description
I’d like for cuDF to support concatenating a series and something array-like into a series similarly to how Pandas functions.
# Example:
```
cudfArray = cudf.concat([cudfSeriesB, cudfSeries], axis=1)
cudfSeries
cudfArray
cudfSeries.str.cat(cudfArray, na_rep="-")
```
# Result:
```
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/opt/conda/envs/rapids/lib/python3.7/site-packages/cudf/core/column/column.py in as_column(arbitrary, nan_as_null, dtype, length)
1950 data = as_column(
-> 1951 memoryview(arbitrary), dtype=dtype, nan_as_null=nan_as_null
1952 )
TypeError: memoryview: a bytes-like object is required, not 'DataFrame'
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
/opt/conda/envs/rapids/lib/python3.7/site-packages/cudf/core/column/column.py in as_column(arbitrary, nan_as_null, dtype, length)
1987 if nan_as_null is None
-> 1988 else nan_as_null,
1989 ),
/opt/conda/envs/rapids/lib/python3.7/site-packages/pyarrow/array.pxi in pyarrow.lib.array()
/opt/conda/envs/rapids/lib/python3.7/site-packages/pyarrow/error.pxi in pyarrow.lib.check_status()
/opt/conda/envs/rapids/lib/python3.7/site-packages/cudf/core/dataframe.py in __arrow_array__(self, type)
1018 raise TypeError(
-> 1019 "Implicit conversion to a host PyArrow Table via __arrow_array__ "
1020 "is not allowed, To explicitly construct a PyArrow Table, "
TypeError: Implicit conversion to a host PyArrow Table via __arrow_array__ is not allowed, To explicitly construct a PyArrow Table, consider using .to_arrow()
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
in
2 cudfSeries
3 cudfArray
----> 4 cudfSeries.str.cat(cudfArray, na_rep="-")
/opt/conda/envs/rapids/lib/python3.7/site-packages/cudf/core/column/string.py in cat(self, others, sep, na_rep)
441 )
442 else:
--> 443 other_cols = _get_cols_list(self._parent, others)
444 all_cols = [self._column] + other_cols
445 data = cpp_concatenate(
/opt/conda/envs/rapids/lib/python3.7/site-packages/cudf/core/column/string.py in _get_cols_list(parent_obj, others)
5198 others = others.reindex(parent_index)
5199
-> 5200 return [column.as_column(others, dtype="str")]
5201 else:
5202 raise TypeError(
/opt/conda/envs/rapids/lib/python3.7/site-packages/cudf/core/column/column.py in as_column(arbitrary, nan_as_null, dtype, length)
1996 data = as_column(sr, nan_as_null=nan_as_null, dtype=dtype)
1997 elif np_type == np.str_:
-> 1998 sr = pd.Series(arbitrary, dtype="str")
1999 data = as_column(sr, nan_as_null=nan_as_null)
2000 else:
/opt/conda/envs/rapids/lib/python3.7/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
325 data = data.copy()
326 else:
--> 327 data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True)
328
329 data = SingleBlockManager.from_array(data, index)
/opt/conda/envs/rapids/lib/python3.7/site-packages/pandas/core/construction.py in sanitize_array(data, index, dtype, copy, raise_cast_failure)
461 subarr = construct_1d_arraylike_from_scalar(data, len(index), dtype)
462 else:
--> 463 subarr = _try_cast(data, dtype, copy, raise_cast_failure)
464
465 # scalar like, GH
/opt/conda/envs/rapids/lib/python3.7/site-packages/pandas/core/construction.py in _try_cast(arr, dtype, copy, raise_cast_failure)
566 subarr = construct_1d_object_array_from_listlike(subarr)
567 elif not is_extension_array_dtype(subarr):
--> 568 subarr = construct_1d_ndarray_preserving_na(subarr, dtype, copy=copy)
569 except OutOfBoundsDatetime:
570 # in case of out of bound datetime64 -> always raise
/opt/conda/envs/rapids/lib/python3.7/site-packages/pandas/core/dtypes/cast.py in construct_1d_ndarray_preserving_na(values, dtype, copy)
1621
1622 if dtype is not None and dtype.kind == "U":
-> 1623 subarr = lib.ensure_string_array(values, convert_na_value=False, copy=copy)
1624 else:
1625 subarr = np.array(values, dtype=dtype, copy=copy)
pandas/_libs/lib.pyx in pandas._libs.lib.ensure_string_array()
pandas/_libs/lib.pyx in pandas._libs.lib.ensure_string_array()
/opt/conda/envs/rapids/lib/python3.7/site-packages/numpy/core/_asarray.py in asarray(a, dtype, order)
81
82 """
---> 83 return array(a, dtype, copy=False, order=order)
84
85
/opt/conda/envs/rapids/lib/python3.7/site-packages/cudf/core/dataframe.py in __array__(self, dtype)
1009 def __array__(self, dtype=None):
1010 raise TypeError(
-> 1011 "Implicit conversion to a host NumPy array via __array__ is not "
1012 "allowed, To explicitly construct a GPU matrix, consider using "
1013 ".as_gpu_matrix()\nTo explicitly construct a host "
TypeError: Implicit conversion to a host NumPy array via __array__ is not allowed, To explicitly construct a GPU matrix, consider using .as_gpu_matrix()
To explicitly construct a host matrix, consider using .as_matrix()
```
**Pandas does this by Concatenating a series and something array-like (dataframe) into a series.:**
```
pandasArray = pd.concat([pandasSeriesB, pandasSeries], axis=1)
pandasSeries
pandasArray
pandasSeries.str.cat(pandasArray, na_rep="-")
```
**A cudf workaround was found doing the following:**
```
cudfArray = cudf.concat([cudfSeriesB, cudfSeries], axis=1)
print(cudfSeries)
print(cudfArray)
print(cudfSeriesB)
#cudfArray = cudfArray.as_matrix()
cudfArray[1].str.cat(cudfArray[0], na_rep="-").str.cat(cudfSeries, na_rep="-")
```
Contributor guide
Assessment
This issue has not been assessed yet.