36
36
37
37
38
38
def from_dataframe (df : DataFrameObject ,
39
- allow_zero_copy : bool = False ) -> pd .DataFrame :
39
+ allow_copy : bool = False ) -> pd .DataFrame :
40
40
"""
41
41
Construct a pandas DataFrame from ``df`` if it supports ``__dataframe__``
42
42
"""
@@ -47,7 +47,7 @@ def from_dataframe(df : DataFrameObject,
47
47
if not hasattr (df , '__dataframe__' ):
48
48
raise ValueError ("`df` does not support __dataframe__" )
49
49
50
- return _from_dataframe (df .__dataframe__ (allow_zero_copy = allow_zero_copy ))
50
+ return _from_dataframe (df .__dataframe__ (allow_copy = allow_copy ))
51
51
52
52
53
53
def _from_dataframe (df : DataFrameObject ) -> pd .DataFrame :
@@ -162,7 +162,7 @@ def convert_categorical_column(col : ColumnObject) -> pd.Series:
162
162
163
163
164
164
def __dataframe__ (cls , nan_as_null : bool = False ,
165
- allow_zero_copy : bool = False ) -> dict :
165
+ allow_copy : bool = False ) -> dict :
166
166
"""
167
167
The public method to attach to pd.DataFrame
168
168
@@ -174,13 +174,13 @@ def __dataframe__(cls, nan_as_null : bool = False,
174
174
This currently has no effect; once support for nullable extension
175
175
dtypes is added, this value should be propagated to columns.
176
176
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
178
178
is going to support striding buffers. It is optional, and the libraries
179
179
do not need to implement it. Currently, if the flag is set to ``True`` it
180
180
will raise a ``RuntimeError``.
181
181
"""
182
182
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 )
184
184
185
185
186
186
# Monkeypatch the Pandas DataFrame class to support the interchange protocol
@@ -195,11 +195,11 @@ class _PandasBuffer:
195
195
Data in the buffer is guaranteed to be contiguous in memory.
196
196
"""
197
197
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 :
199
199
"""
200
200
Handle only regular columns (= numpy arrays) for now.
201
201
"""
202
- if allow_zero_copy :
202
+ if allow_copy :
203
203
# Array is not contiguous and strided buffers do not need to be
204
204
# supported. It brings some extra complexity for libraries that
205
205
# don't support it (e.g. Arrow).
@@ -260,7 +260,7 @@ class _PandasColumn:
260
260
"""
261
261
262
262
def __init__ (self , column : pd .Series ,
263
- allow_zero_copy : bool = False ) -> None :
263
+ allow_copy : bool = False ) -> None :
264
264
"""
265
265
Note: doesn't deal with extension arrays yet, just assume a regular
266
266
Series/ndarray for now.
@@ -271,7 +271,7 @@ def __init__(self, column : pd.Series,
271
271
272
272
# Store the column as a private attribute
273
273
self ._col = column
274
- self ._allow_zero_copy = allow_zero_copy
274
+ self ._allow_copy = allow_copy
275
275
276
276
@property
277
277
def size (self ) -> int :
@@ -457,12 +457,12 @@ def get_data_buffer(self) -> Tuple[_PandasBuffer, Any]: # Any is for self.dtype
457
457
_k = _DtypeKind
458
458
if self .dtype [0 ] in (_k .INT , _k .UINT , _k .FLOAT , _k .BOOL ):
459
459
buffer = _PandasBuffer (
460
- self ._col .to_numpy (), allow_zero_copy = self ._allow_zero_copy )
460
+ self ._col .to_numpy (), allow_copy = self ._allow_copy )
461
461
dtype = self .dtype
462
462
elif self .dtype [0 ] == _k .CATEGORICAL :
463
463
codes = self ._col .values .codes
464
464
buffer = _PandasBuffer (
465
- codes , allow_zero_copy = self ._allow_zero_copy )
465
+ codes , allow_copy = self ._allow_copy )
466
466
dtype = self ._dtype_from_pandasdtype (codes .dtype )
467
467
else :
468
468
raise NotImplementedError (f"Data type { self ._col .dtype } not handled yet" )
@@ -496,7 +496,7 @@ class _PandasDataFrame:
496
496
attributes defined on this class.
497
497
"""
498
498
def __init__ (self , df : pd .DataFrame , nan_as_null : bool = False ,
499
- allow_zero_copy : bool = False ) -> None :
499
+ allow_copy : bool = False ) -> None :
500
500
"""
501
501
Constructor - an instance of this (private) class is returned from
502
502
`pd.DataFrame.__dataframe__`.
@@ -507,7 +507,7 @@ def __init__(self, df : pd.DataFrame, nan_as_null : bool = False,
507
507
# This currently has no effect; once support for nullable extension
508
508
# dtypes is added, this value should be propagated to columns.
509
509
self ._nan_as_null = nan_as_null
510
- self ._allow_zero_copy = allow_zero_copy
510
+ self ._allow_copy = allow_copy
511
511
512
512
def num_columns (self ) -> int :
513
513
return len (self ._df .columns )
@@ -523,14 +523,14 @@ def column_names(self) -> Iterable[str]:
523
523
524
524
def get_column (self , i : int ) -> _PandasColumn :
525
525
return _PandasColumn (
526
- self ._df .iloc [:, i ], allow_zero_copy = self ._allow_zero_copy )
526
+ self ._df .iloc [:, i ], allow_copy = self ._allow_copy )
527
527
528
528
def get_column_by_name (self , name : str ) -> _PandasColumn :
529
529
return _PandasColumn (
530
- self ._df [name ], allow_zero_copy = self ._allow_zero_copy )
530
+ self ._df [name ], allow_copy = self ._allow_copy )
531
531
532
532
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 )
534
534
for name in self ._df .columns ]
535
535
536
536
def select_columns (self , indices : Sequence [int ]) -> '_PandasDataFrame' :
@@ -574,7 +574,7 @@ def test_noncontiguous_columns():
574
574
df = pd .DataFrame (arr )
575
575
assert df [0 ].to_numpy ().strides == (24 ,)
576
576
with pytest .raises (RuntimeError ):
577
- df2 = from_dataframe (df , allow_zero_copy = True )
577
+ df2 = from_dataframe (df , allow_copy = True )
578
578
579
579
580
580
def test_categorical_dtype ():
0 commit comments