Skip to content

Commit

Permalink
FIX-#7357: Fix NoAttributeError on DataFrame.copy (#7358)
Browse files Browse the repository at this point in the history
Signed-off-by: Devin Petersohn <devin.petersohn@snowflake.com>
  • Loading branch information
devin-petersohn authored Aug 2, 2024
1 parent 6dce30e commit b236b76
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions modin/polars/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ def __getitem__(self, item):

return Series(_query_compiler=self._query_compiler.getitem_array([item]))

def _copy(self):
return self.__constructor__(_query_compiler=self._query_compiler.copy())

def _to_polars(self) -> polars.DataFrame:
"""
Convert the DataFrame to Polars format.
Expand Down Expand Up @@ -266,7 +269,7 @@ def _convert_non_numeric_to_null(self):
need_columns_reindex=False,
).astype({c: self._query_compiler.dtypes[c] for c in non_numeric_cols})
)
return self.copy()
return self._copy()

def mean(self, *, axis=None, null_strategy="ignore"):
"""
Expand Down Expand Up @@ -956,7 +959,7 @@ def rechunk(self) -> "DataFrame":
Returns:
Rechunked DataFrame.
"""
return self.copy()
return self._copy()

def rename(self, mapping: dict[str, str] | callable) -> "DataFrame":
"""
Expand All @@ -972,7 +975,7 @@ def rename(self, mapping: dict[str, str] | callable) -> "DataFrame":
mapping = {c: mapping(c) for c in self.columns}
# TODO: add a query compiler method for `rename`
new_columns = {c: mapping.get(c, c) for c in self.columns}
new_obj = self.copy()
new_obj = self._copy()
new_obj.columns = new_columns
return new_obj

Expand Down Expand Up @@ -1076,7 +1079,7 @@ def set_sorted(
if isinstance(column, str):
column = [column]
new_sorted_columns = [c in column for c in self.columns]
obj = self.copy()
obj = self._copy()
obj._sorted_columns = new_sorted_columns
return obj

Expand Down Expand Up @@ -1231,7 +1234,7 @@ def with_row_index(self, name: str = "index", offset: int = 0) -> "DataFrame":
DataFrame with the row index added.
"""
if offset != 0:
obj = self.copy()
obj = self._copy()
obj.index = obj.index + offset
result = self.__constructor__(
_query_compiler=self._query_compiler.reset_index(drop=False)
Expand Down

0 comments on commit b236b76

Please sign in to comment.