Skip to content

Commit

Permalink
reset label_dtype after empty
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke committed Aug 12, 2024
1 parent 2907de9 commit 6234b85
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,13 @@ def _setitem_tuple_arg(self, key, value):
try:
columns_df = self._frame._get_columns_by_label(key[1])
except KeyError:
if not self._frame.empty and isinstance(key[0], slice):
was_empty = self._frame.empty
if not was_empty and isinstance(key[0], slice):
pos_range = _get_label_range_or_mask(
self._frame.index, key[0].start, key[0].stop, key[0].step
)
idx = self._frame.index[pos_range]
elif self._frame.empty and isinstance(key[0], slice):
elif was_empty and isinstance(key[0], slice):
idx = None
else:
if is_scalar(key[0]):
Expand All @@ -396,6 +397,9 @@ def _setitem_tuple_arg(self, key, value):
idx if idx is not None else cudf.RangeIndex(len(new_col))
)
self._frame._data.insert(key[1], new_col)
if was_empty:
# TODO: Create a cudf_to_pandas_dtype function to use here
self._frame._data.label_dtype = None
else:
if is_scalar(value):
for col in columns_df._column_names:
Expand Down Expand Up @@ -3308,7 +3312,9 @@ def _insert(self, loc, name, value, nan_as_null=None, ignore_index=True):
dtype=dtype,
)

was_empty = False
if len(self) == 0:
was_empty = True
if isinstance(value, (pd.Series, Series)):
if not ignore_index:
self.index = cudf.Index(value.index)
Expand Down Expand Up @@ -3338,6 +3344,9 @@ def _insert(self, loc, name, value, nan_as_null=None, ignore_index=True):
value = column.as_column(value, nan_as_null=nan_as_null)

self._data.insert(name, value, loc=loc)
if was_empty:
# TODO: Create a cudf_to_pandas_dtype function to use here
self._data.label_dtype = None

@property # type:ignore
@_performance_tracking
Expand Down

0 comments on commit 6234b85

Please sign in to comment.