Skip to content

Commit ab48fec

Browse files
committed
Mimick what Modin did
Signed-off-by: Vasily Litvinov <vasilij.n.litvinov@intel.com>
1 parent bb5a009 commit ab48fec

File tree

8 files changed

+664
-311
lines changed

8 files changed

+664
-311
lines changed

pandas/api/exchange/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Public API for DataFrame exchange protocol.
33
"""
44

5-
from pandas.core.exchange.implementation import from_dataframe
5+
from pandas.core.exchange.from_dataframe import from_dataframe
66
from pandas.core.exchange.dataframe_protocol import DataFrame
77

88
__all__ = ["from_dataframe", "DataFrame"]

pandas/core/exchange/buffer.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
from pandas.core.exchange.dataframe_protocol import Buffer, DlpackDeviceType, DtypeKind
22
import numpy as np
33
from typing import Tuple
4-
import ctypes
5-
6-
7-
_NP_DTYPES = {
8-
DtypeKind.INT: {8: np.int8, 16: np.int16, 32: np.int32, 64: np.int64},
9-
DtypeKind.UINT: {8: np.uint8, 16: np.uint16, 32: np.uint32, 64: np.uint64},
10-
DtypeKind.FLOAT: {32: np.float32, 64: np.float64},
11-
DtypeKind.BOOL: {8: bool},
12-
}
134

145

156
class PandasBuffer(Buffer):
@@ -74,25 +65,3 @@ def __repr__(self) -> str:
7465
)
7566
+ ")"
7667
)
77-
78-
79-
def buffer_to_ndarray(_buffer: Buffer, _dtype) -> np.ndarray:
80-
# Handle the dtype
81-
kind = _dtype[0]
82-
bitwidth = _dtype[1]
83-
if kind not in _NP_DTYPES:
84-
raise RuntimeError(f"Unsupported data type: {kind}")
85-
86-
column_dtype = _NP_DTYPES[kind][bitwidth]
87-
88-
# No DLPack yet, so need to construct a new ndarray from the data pointer
89-
# and size in the buffer plus the dtype on the column
90-
ctypes_type = np.ctypeslib.as_ctypes_type(column_dtype)
91-
data_pointer = ctypes.cast(_buffer.ptr, ctypes.POINTER(ctypes_type))
92-
93-
# NOTE: `x` does not own its memory, so the caller of this function must
94-
# either make a copy or hold on to a reference of the column or
95-
# buffer! (not done yet, this is pretty awful ...)
96-
x = np.ctypeslib.as_array(data_pointer, shape=(_buffer.bufsize // (bitwidth // 8),))
97-
98-
return x

0 commit comments

Comments
 (0)