Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX-#7357: Fix NoAttributeError on DataFrame.copy #7358

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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

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

Check warning on line 108 in modin/polars/dataframe.py

View check run for this annotation

Codecov / codecov/patch

modin/polars/dataframe.py#L108

Added line #L108 was not covered by tests

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

Check warning on line 272 in modin/polars/dataframe.py

View check run for this annotation

Codecov / codecov/patch

modin/polars/dataframe.py#L272

Added line #L272 was not covered by tests

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

Check warning on line 962 in modin/polars/dataframe.py

View check run for this annotation

Codecov / codecov/patch

modin/polars/dataframe.py#L962

Added line #L962 was not covered by tests

def rename(self, mapping: dict[str, str] | callable) -> "DataFrame":
"""
Expand All @@ -972,7 +975,7 @@
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()

Check warning on line 978 in modin/polars/dataframe.py

View check run for this annotation

Codecov / codecov/patch

modin/polars/dataframe.py#L978

Added line #L978 was not covered by tests
new_obj.columns = new_columns
return new_obj

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

Check warning on line 1082 in modin/polars/dataframe.py

View check run for this annotation

Codecov / codecov/patch

modin/polars/dataframe.py#L1082

Added line #L1082 was not covered by tests
obj._sorted_columns = new_sorted_columns
return obj

Expand Down Expand Up @@ -1231,7 +1234,7 @@
DataFrame with the row index added.
"""
if offset != 0:
obj = self.copy()
obj = self._copy()

Check warning on line 1237 in modin/polars/dataframe.py

View check run for this annotation

Codecov / codecov/patch

modin/polars/dataframe.py#L1237

Added line #L1237 was not covered by tests
obj.index = obj.index + offset
result = self.__constructor__(
_query_compiler=self._query_compiler.reset_index(drop=False)
Expand Down
Loading