8000 Rename keyword to allow_copy · data-apis/dataframe-api@04bbe1b · GitHub
[go: up one dir, main page]

Skip to content

Commit 04bbe1b

Browse files
committed
Rename keyword to allow_copy
1 parent 5773efc commit 04bbe1b

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

protocol/dataframe_protocol.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class DataFrame:
336336
to the dataframe interchange protocol specification.
337337
"""
338338
def __dataframe__(self, nan_as_null : bool = False,
339-
allow_zero_copy : bool = True) -> dict:
339+
allow_copy : bool = True) -> dict:
340340
"""
341341
Produces a dictionary object following the dataframe protocol spec
342342
@@ -345,12 +345,12 @@ def __dataframe__(self, nan_as_null : bool = False,
345345
It is intended for cases where the consumer does not support the bit
346346
mask or byte mask that is the producer's native representation.
347347
348-
``allow_zero_copy`` is a keyword that defines if the given implementation
348+
``allow_copy`` is a keyword that defines if the given implementation
349349
is going to support striding buffers. It is optional, and the libraries
350350
do not need to implement it.
351351
"""
352352
self._nan_as_null = nan_as_null
353-
self._allow_zero_zopy = allow_zero_copy
353+
self._allow_zero_zopy = allow_copy
354354
return {
355355
"dataframe": self, # DataFrame object adhering to the protocol
356356
"version": 0 # Version number of the protocol

protocol/pandas_implementation.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737

3838
def from_dataframe(df : DataFrameObject,
39-
allow_zero_copy : bool = False) -> pd.DataFrame:
39+
allow_copy : bool = False) -> pd.DataFrame:
4040
"""
4141
Construct a pandas DataFrame from ``df`` if it supports ``__dataframe__``
4242
"""
@@ -47,7 +47,7 @@ def from_dataframe(df : DataFrameObject,
4747
if not hasattr(df, '__dataframe__'):
4848
raise ValueError("`df` does not support __dataframe__")
4949

50-
return _from_dataframe(df.__dataframe__(allow_zero_copy=allow_zero_copy))
50+
return _from_dataframe(df.__dataframe__(allow_copy=allow_copy))
5151

5252

5353
def _from_dataframe(df : DataFrameObject) -> pd.DataFrame:
@@ -162,7 +162,7 @@ def convert_categorical_column(col : ColumnObject) -> pd.Series:
162162

163163

164164
def __dataframe__(cls, nan_as_null : bool = False,
165-
allow_zero_copy : bool = False) -> dict:
165+
allow_copy : bool = False) -> dict:
166166
"""
167167
The public method to attach to pd.DataFrame
168168
@@ -174,13 +174,13 @@ def __dataframe__(cls, nan_as_null : bool = False,
174174
This currently has no effect; once support for nullable extension
175175
dtypes is added, this value should be propagated to columns.
176176
177-
``allow_zero_copy`` is a keyword that defines if the given implementation
177+
``allow_copy`` is a keyword that defines if the given implementation
178178
is going to support striding buffers. It is optional, and the libraries
179179
do not need to implement it. Currently, if the flag is set to ``True`` it
180180
will raise a ``RuntimeError``.
181181
"""
182182
return _PandasDataFrame(
183-
cls, nan_as_null=nan_as_null, allow_zero_copy=allow_zero_copy)
183+
cls, nan_as_null=nan_as_null, allow_copy=allow_copy)
184184

185185

186186
# Monkeypatch the Pandas DataFrame class to support the interchange protocol
@@ -195,11 +195,11 @@ class _PandasBuffer:
195195
Data in the buffer is guaranteed to be contiguous in memory.
196196
"""
197197

198-
def __init__(self, x : np.ndarray, allow_zero_copy : bool = False) -> None:
198+
def __init__(self, x : np.ndarray, allow_copy : bool = False) -> None:
199199
"""
200200
Handle only regular columns (= numpy arrays) for now.
201201
"""
202-
if allow_zero_copy:
202+
if allow_copy:
203203
# Array is not contiguous and strided buffers do not need to be
204204
# supported. It brings some extra complexity for libraries that
205205
# don't support it (e.g. Arrow).
@@ -260,7 +260,7 @@ class _PandasColumn:
260260
"""
261261

262262
def __init__(self, column : pd.Series,
263-
allow_zero_copy : bool = False) -> None:
263+
allow_copy : bool = False) -> None:
264264
"""
265265
Note: doesn't deal with extension arrays yet, just assume a regular
266266
Series/ndarray for now.
@@ -271,7 +271,7 @@ def __init__(self, column : pd.Series,
271271

272272
# Store the column as a private attribute
273273
self._col = column
274-
self._allow_zero_copy = allow_zero_copy
274+
self._allow_copy = allow_copy
275275

276276
@property
277277
def size(self) -> int:
@@ -457,12 +457,12 @@ def get_data_buffer(self) -> Tuple[_PandasBuffer, Any]: # Any is for self.dtype
457457
_k = _DtypeKind
458458
if self.dtype[0] in (_k.INT, _k.UINT, _k.FLOAT, _k.BOOL):
459459
buffer = _PandasBuffer(
460-
self._col.to_numpy(), allow_zero_copy=self._allow_zero_copy)
460+
self._col.to_numpy(), allow_copy=self._allow_copy)
461461
dtype = self.dtype
462462
elif self.dtype[0] == _k.CATEGORICAL:
463463
codes = self._col.values.codes
464464
buffer = _PandasBuffer(
465-
codes, allow_zero_copy=self._allow_zero_copy)
465+
codes, allow_copy=self._allow_copy)
466466
dtype = self._dtype_from_pandasdtype(codes.dtype)
467467
else:
468468
raise NotImplementedError(f"Data type {self._col.dtype} not handled yet")
@@ -496,7 +496,7 @@ class _PandasDataFrame:
496496
attributes defined on this class.
497497
"""
498498
def __init__(self, df : pd.DataFrame, nan_as_null : bool = False,
499-
allow_zero_copy : bool = False) -> None:
499+
allow_copy : bool = False) -> None:
500500
"""
501501
Constructor - an instance of this (private) class is returned from
502502
`pd.DataFrame.__dataframe__`.
@@ -507,7 +507,7 @@ def __init__(self, df : pd.DataFrame, nan_as_null : bool = False,
507507
# This currently has no effect; once support for nullable extension
508508
# dtypes is added, this value should be propagated to columns.
509509
self._nan_as_null = nan_as_null
510-
self._allow_zero_copy = allow_zero_copy
510+
self._allow_copy = allow_copy
511511

512512
def num_columns(self) -> int:
513513
return len(self._df.columns)
@@ -523,14 +523,14 @@ def column_names(self) -> Iterable[str]:
523523

524524
def get_column(self, i: int) -> _PandasColumn:
525525
return _PandasColumn(
526-
self._df.iloc[:, i], allow_zero_copy=self._allow_zero_copy)
526+
self._df.iloc[:, i], allow_copy=self._allow_copy)
527527

528528
def get_column_by_name(self, name: str) -> _PandasColumn:
529529
return _PandasColumn(
530-
self._df[name], allow_zero_copy=self._allow_zero_copy)
530+
self._df[name], allow_copy=self._allow_copy)
531531

532532
def get_columns(self) -> Iterable[_PandasColumn]:
533-
return [_PandasColumn(self._df[name], allow_zero_copy=self._allow_zero_copy)
533+
return [_PandasColumn(self._df[name], allow_copy=self._allow_copy)
534534
for name in self._df.columns]
535535

536536
def select_columns(self, indices: Sequence[int]) -> '_PandasDataFrame':
@@ -574,7 +574,7 @@ def test_noncontiguous_columns():
574574
df = pd.DataFrame(arr)
575575
assert df[0].to_numpy().strides == (24,)
576576
with pytest.raises(RuntimeError):
577-
df2 = from_dataframe(df, allow_zero_copy=True)
577+
df2 = from_dataframe(df, allow_copy=True)
578578

579579

580580
def test_categorical_dtype():

0 commit comments

Comments
 (0)
0