Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 693ed8c

Browse files
authoredFeb 21, 2025
feat: Support DF.__array__(copy=True) (#1403)
1 parent 650a190 commit 693ed8c

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed
 

‎bigframes/dataframe.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3705,7 +3705,9 @@ def to_numpy(
37053705
) -> numpy.ndarray:
37063706
return self.to_pandas().to_numpy(dtype, copy, na_value, **kwargs)
37073707

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

37113713
__array__.__doc__ = inspect.getdoc(vendored_pandas_frame.DataFrame.__array__)

‎bigframes/series.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,9 @@ def to_numpy(
18121812
) -> numpy.ndarray:
18131813
return self.to_pandas().to_numpy(dtype, copy, na_value, **kwargs)
18141814

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

18181820
__array__.__doc__ = inspect.getdoc(vendored_pandas_series.Series.__array__)

‎third_party/bigframes_vendored/pandas/core/frame.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7179,7 +7179,7 @@ def __len__(self):
71797179
"""
71807180
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
71817181

7182-
def __array__(self):
7182+
def __array__(self, dtype=None, copy: Optional[bool] = None):
71837183
"""
71847184
Returns the rows as NumPy array.
71857185
@@ -7210,6 +7210,8 @@ def __array__(self):
72107210
dtype (str or numpy.dtype, optional):
72117211
The dtype to use for the resulting NumPy array. By default,
72127212
the dtype is inferred from the data.
7213+
copy (bool or None, optional):
7214+
Whether to copy the data, False is not supported.
72137215
72147216
Returns:
72157217
numpy.ndarray:

‎third_party/bigframes_vendored/pandas/core/series.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -5941,7 +5941,7 @@ def size(self) -> int:
59415941
"""
59425942
raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE)
59435943

5944-
def __array__(self, dtype=None) -> numpy.ndarray:
5944+
def __array__(self, dtype=None, copy: Optional[bool] = None) -> numpy.ndarray:
59455945
"""
59465946
Returns the values as NumPy array.
59475947
@@ -5965,6 +5965,8 @@ def __array__(self, dtype=None) -> numpy.ndarray:
59655965
dtype (str or numpy.dtype, optional):
59665966
The dtype to use for the resulting NumPy array. By default,
59675967
the dtype is inferred from the data.
5968+
copy (bool or None, optional):
5969+
Whether to copy the data, False is not supported.
59685970
59695971
Returns:
59705972
numpy.ndarray:

0 commit comments

Comments
 (0)
Failed to load comments.