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

feat: Support DF.__array__(copy=True) #1403

Merged
merged 3 commits into from
Feb 21, 2025
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
4 changes: 3 additions & 1 deletion bigframes/dataframe.py
Original file line number Diff line number Diff line change
@@ -3705,7 +3705,9 @@ def to_numpy(
) -> numpy.ndarray:
return self.to_pandas().to_numpy(dtype, copy, na_value, **kwargs)

def __array__(self, dtype=None) -> numpy.ndarray:
def __array__(self, dtype=None, copy: Optional[bool] = None) -> numpy.ndarray:
if copy is False:
raise ValueError("Cannot convert to array without copy.")
return self.to_numpy(dtype=dtype)

__array__.__doc__ = inspect.getdoc(vendored_pandas_frame.DataFrame.__array__)
4 changes: 3 additions & 1 deletion bigframes/series.py
Original file line number Diff line number Diff line change
@@ -1812,7 +1812,9 @@ def to_numpy(
) -> numpy.ndarray:
return self.to_pandas().to_numpy(dtype, copy, na_value, **kwargs)

def __array__(self, dtype=None) -> numpy.ndarray:
def __array__(self, dtype=None, copy: Optional[bool] = None) -> numpy.ndarray:
if copy is False:
raise ValueError("Cannot convert to array without copy.")
return self.to_numpy(dtype=dtype)

__array__.__doc__ = inspect.getdoc(vendored_pandas_series.Series.__array__)
4 changes: 3 additions & 1 deletion third_party/bigframes_vendored/pandas/core/frame.py
Original file line number Diff line number Diff line change
@@ -7179,7 +7179,7 @@ def __len__(self):
"""
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)

def __array__(self):
def __array__(self, dtype=None, copy: Optional[bool] = None):
"""
Returns the rows as NumPy array.

@@ -7210,6 +7210,8 @@ def __array__(self):
dtype (str or numpy.dtype, optional):
The dtype to use for the resulting NumPy array. By default,
the dtype is inferred from the data.
copy (bool or None, optional):
Whether to copy the data, False is not supported.

Returns:
numpy.ndarray:
4 changes: 3 additions & 1 deletion third_party/bigframes_vendored/pandas/core/series.py
Original file line number Diff line number Diff line change
@@ -5941,7 +5941,7 @@ def size(self) -> int:
"""
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)

def __array__(self, dtype=None) -> numpy.ndarray:
def __array__(self, dtype=None, copy: Optional[bool] = None) -> numpy.ndarray:
"""
Returns the values as NumPy array.

@@ -5965,6 +5965,8 @@ def __array__(self, dtype=None) -> numpy.ndarray:
dtype (str or numpy.dtype, optional):
The dtype to use for the resulting NumPy array. By default,
the dtype is inferred from the data.
copy (bool or None, optional):
Whether to copy the data, False is not supported.

Returns:
numpy.ndarray: