Skip to content

Commit

Permalink
change constructor calls
Browse files Browse the repository at this point in the history
  • Loading branch information
galipremsagar committed Feb 7, 2022
1 parent ded9906 commit b565aaa
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _return_or_inplace(
idx.names = None
return idx
else:
return self._parent._constructor_expanddim(
return self._parent._constructor_expanddim._from_data(
data=table._data, index=self._parent.index
)
elif isinstance(self._parent, cudf.Series):
Expand Down
11 changes: 6 additions & 5 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class _DataFrameIlocIndexer(_DataFrameIndexer):
def _getitem_tuple_arg(self, arg):
# Iloc Step 1:
# Gather the columns specified by the second tuple arg
columns_df = DataFrame(self._frame._get_columns_by_index(arg[1]))
columns_df = self._frame._get_columns_by_index(arg[1])

columns_df._index = self._frame._index

Expand Down Expand Up @@ -399,7 +399,7 @@ def _getitem_tuple_arg(self, arg):

@annotate("ILOC_SETITEM", color="blue", domain="cudf_python")
def _setitem_tuple_arg(self, key, value):
columns = DataFrame(self._frame._get_columns_by_index(key[1]))
columns = self._frame._get_columns_by_index(key[1])

for col in columns:
self._frame[col].iloc[key[0]] = value
Expand Down Expand Up @@ -569,9 +569,10 @@ def __init__(
}
)
elif isinstance(data, ColumnAccessor):
result = self._from_data(data, index, columns)
self._data = result._data
self._index = result._index
raise TypeError(
"Use cudf.Series._from_data for constructing a Series from "
"ColumnAccessor"
)
elif hasattr(data, "__cuda_array_interface__"):
arr_interface = data.__cuda_array_interface__

Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def _get_columns_by_index(self, indices):
"""
data = self._data.select_by_index(indices)
return self.__class__(
return self.__class__._from_data(
data, columns=data.to_pandas_index(), index=self.index
)

Expand Down
14 changes: 9 additions & 5 deletions python/cudf/cudf/core/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def concat(objs, axis=0, join="outer", ignore_index=False, sort=None):

if ignore_index:
if axis == 1:
result = cudf.DataFrame(
result = cudf.DataFrame._from_data(
data=obj._data.copy(deep=True),
index=obj.index.copy(deep=True),
)
Expand All @@ -249,13 +249,17 @@ def concat(objs, axis=0, join="outer", ignore_index=False, sort=None):
# after construction.
result.columns = pd.RangeIndex(len(obj._data.names))
elif axis == 0:
if isinstance(obj, (pd.Series, cudf.Series)):
result = cudf.Series(
if isinstance(obj, cudf.Series):
result = cudf.Series._from_data(
data=obj._data.copy(deep=True),
index=cudf.RangeIndex(len(obj)),
)
elif isinstance(obj, pd.Series):
result = cudf.Series(
data=obj, index=cudf.RangeIndex(len(obj)),
)
else:
result = cudf.DataFrame(
result = cudf.DataFrame._from_data(
data=obj._data.copy(deep=True),
index=cudf.RangeIndex(len(obj)),
)
Expand Down Expand Up @@ -370,7 +374,7 @@ def concat(objs, axis=0, join="outer", ignore_index=False, sort=None):
return cudf.DataFrame()
elif len(objs) == 1:
obj = objs[0]
result = cudf.DataFrame(
result = cudf.DataFrame._from_data(
data=None if join == "inner" else obj._data.copy(deep=True),
index=cudf.RangeIndex(len(obj))
if ignore_index
Expand Down
7 changes: 5 additions & 2 deletions python/cudf/cudf/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,10 @@ def __init__(
if dtype is not None:
data = data.astype(dtype)
elif isinstance(data, ColumnAccessor):
name, data = data.names[0], data.columns[0]
raise TypeError(
"Use cudf.Series._from_data for constructing a Series from "
"ColumnAccessor"
)

if isinstance(data, Series):
index = data._index if index is None else index
Expand Down Expand Up @@ -579,7 +582,7 @@ def _get_columns_by_label(self, labels, downcast=False):
new_data = super()._get_columns_by_label(labels, downcast)

return (
self.__class__(data=new_data, index=self.index)
self.__class__._from_data(data=new_data, index=self.index)
if len(new_data) > 0
else self.__class__(dtype=self.dtype, name=self.name)
)
Expand Down
8 changes: 4 additions & 4 deletions python/cudf/cudf/tests/test_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def assert_packed_frame_equality(df):
packed = pack(df)
del df
tbl = unpack(packed)
unpacked = DataFrame(tbl._data, tbl._index)
unpacked = DataFrame._from_data(tbl._data, tbl._index)

assert_eq(unpacked, pdf)

Expand Down Expand Up @@ -198,14 +198,14 @@ def check_packed_pickled_equality(df):
for b in buffers:
assert isinstance(b, pickle.PickleBuffer)
tbl = unpack(pickle.loads(serialbytes, buffers=buffers))
loaded = DataFrame(tbl._data, tbl._index)
loaded = DataFrame._from_data(tbl._data, tbl._index)
assert_eq(loaded, df)


def assert_packed_frame_picklable(df):
serialbytes = pickle.dumps(pack(df))
tbl = unpack(pickle.loads(serialbytes))
loaded = DataFrame(tbl._data, tbl._index)
loaded = DataFrame._from_data(tbl._data, tbl._index)
assert_eq(loaded, df)


Expand Down Expand Up @@ -271,7 +271,7 @@ def assert_packed_frame_serializable(df):
packed = pack(df)
header, frames = packed.serialize()
tbl = unpack(packed.deserialize(header, frames))
loaded = DataFrame(tbl._data, tbl._index)
loaded = DataFrame._from_data(tbl._data, tbl._index)
assert_eq(loaded, df)


Expand Down

0 comments on commit b565aaa

Please sign in to comment.