Skip to content

Commit a366371

Browse files
Update the version of the DataFrame API protocol to use typing
constraints that are compatible with older versions of Python.
1 parent a092cfc commit a366371

File tree

4 files changed

+404
-128
lines changed

4 files changed

+404
-128
lines changed

src/oracledb/interchange/buffer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
# Implements the Buffer class as documented in DataFrame API
2929
# -----------------------------------------------------------------------------
3030

31+
from typing import Tuple
32+
3133
from .protocol import (
3234
Buffer,
3335
DlpackDeviceType,
@@ -53,7 +55,7 @@ def __dlpack__(self):
5355
"""
5456
raise NotImplementedError("__dlpack__")
5557

56-
def __dlpack_device__(self) -> tuple[DlpackDeviceType, None]:
58+
def __dlpack_device__(self) -> Tuple[DlpackDeviceType, None]:
5759
"""
5860
Device type and device ID for where the data
5961
in the buffer resides

src/oracledb/interchange/column.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@
2828
# Implements the Column class as documented in DataFrame API
2929
# -----------------------------------------------------------------------------
3030

31-
from typing import Any, Iterable, Optional
31+
from typing import Any, Dict, Iterable, Optional, Tuple
3232

3333
from .buffer import OracleColumnBuffer
3434
from .protocol import (
35+
CategoricalDescription,
3536
Column,
3637
Dtype,
3738
ColumnBuffers,
3839
ColumnNullType,
3940
DtypeKind,
40-
Endianness,
4141
)
4242

4343
from .nanoarrow_bridge import (
@@ -88,7 +88,7 @@ def _offsets_buffer(self):
8888
offsets_buffer = OracleColumnBuffer(
8989
size_in_bytes=size_bytes, address=address, buffer_type="offsets"
9090
)
91-
dtype = (DtypeKind.INT, 32, "i", Endianness.NATIVE)
91+
dtype = (DtypeKind.INT, 32, "i", "=")
9292
return offsets_buffer, dtype
9393

9494
def _validity_buffer(self):
@@ -99,11 +99,17 @@ def _validity_buffer(self):
9999
validity_buffer = OracleColumnBuffer(
100100
size_in_bytes=size_bytes, address=address, buffer_type="validity"
101101
)
102-
dtype = (DtypeKind.BOOL, 1, "b", Endianness.NATIVE)
102+
dtype = (DtypeKind.BOOL, 1, "b", "=")
103103
return validity_buffer, dtype
104104

105+
def describe_categorical(self) -> CategoricalDescription:
106+
"""
107+
Returns a description of a categorical data type.
108+
"""
109+
raise NotImplementedError()
110+
105111
@property
106-
def describe_null(self) -> tuple[ColumnNullType, Optional[int]]:
112+
def describe_null(self) -> Tuple[ColumnNullType, Optional[int]]:
107113
"""
108114
Returns a description of the null representation used by the column.
109115
"""
@@ -119,29 +125,29 @@ def dtype(self) -> Dtype:
119125
information on the storage format and the type of data in the column.
120126
"""
121127
if self.ora_arrow_array.arrow_type == NANOARROW_TYPE_INT64:
122-
return (DtypeKind.INT, 64, "l", Endianness.NATIVE)
128+
return (DtypeKind.INT, 64, "l", "=")
123129
elif self.ora_arrow_array.arrow_type == NANOARROW_TYPE_DOUBLE:
124-
return (DtypeKind.FLOAT, 64, "g", Endianness.NATIVE)
130+
return (DtypeKind.FLOAT, 64, "g", "=")
125131
elif self.ora_arrow_array.arrow_type == NANOARROW_TYPE_FLOAT:
126-
return (DtypeKind.FLOAT, 64, "g", Endianness.NATIVE)
132+
return (DtypeKind.FLOAT, 64, "g", "=")
127133
elif self.ora_arrow_array.arrow_type == NANOARROW_TYPE_STRING:
128-
return (DtypeKind.STRING, 8, "u", Endianness.NATIVE)
134+
return (DtypeKind.STRING, 8, "u", "=")
129135
elif self.ora_arrow_array.arrow_type == NANOARROW_TYPE_TIMESTAMP:
130136
if self.ora_arrow_array.time_unit == NANOARROW_TIME_UNIT_MICRO:
131-
return (DtypeKind.DATETIME, 64, "tsu:", Endianness.NATIVE)
137+
return (DtypeKind.DATETIME, 64, "tsu:", "=")
132138
elif self.ora_arrow_array.time_unit == NANOARROW_TIME_UNIT_SECOND:
133-
return (DtypeKind.DATETIME, 64, "tss:", Endianness.NATIVE)
139+
return (DtypeKind.DATETIME, 64, "tss:", "=")
134140
elif self.ora_arrow_array.time_unit == NANOARROW_TIME_UNIT_MILLI:
135-
return (DtypeKind.DATETIME, 64, "tsm:", Endianness.NATIVE)
141+
return (DtypeKind.DATETIME, 64, "tsm:", "=")
136142
elif self.ora_arrow_array.time_unit == NANOARROW_TIME_UNIT_NANO:
137-
return (DtypeKind.DATETIME, 64, "tsn:", Endianness.NATIVE)
143+
return (DtypeKind.DATETIME, 64, "tsn:", "=")
138144
elif self.ora_arrow_array.arrow_type == NANOARROW_TYPE_DECIMAL128:
139145
array = self.ora_arrow_array
140146
return (
141147
DtypeKind.DECIMAL,
142148
128,
143149
f"d:{array.precision}.{array.scale}",
144-
Endianness.NATIVE,
150+
"=",
145151
)
146152

147153
def get_buffers(self) -> ColumnBuffers:
@@ -166,7 +172,7 @@ def get_chunks(self, n_chunks: Optional[int] = None) -> Iterable[Column]:
166172
yield self
167173

168174
@property
169-
def metadata(self) -> dict[str, Any]:
175+
def metadata(self) -> Dict[str, Any]:
170176
"""
171177
Returns metadata about the column.
172178
"""

src/oracledb/interchange/dataframe.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# https://data-apis.org/dataframe-protocol/latest/API.html
3030
# -----------------------------------------------------------------------------
3131

32-
from typing import Any, Dict, Iterable, List, Optional
32+
from typing import Any, Dict, Iterable, List, Optional, Sequence
3333

3434
from .column import OracleColumn
3535

@@ -149,3 +149,15 @@ def num_rows(self) -> int:
149149
Returns the number of rows in the data frame.
150150
"""
151151
return self._rows
152+
153+
def select_columns(self, indices: Sequence[int]) -> "DataFrame":
154+
"""
155+
Create a new DataFrame by selecting a subset of columns by index.
156+
"""
157+
raise NotImplementedError()
158+
159+
def select_columns_by_name(self, names: Sequence[str]) -> "DataFrame":
160+
"""
161+
Create a new DataFrame by selecting a subset of columns by name.
162+
"""
163+
raise NotImplementedError()

0 commit comments

Comments
 (0)