Skip to content

Commit 2ef976c

Browse files
authored
BUG: Fix more interchange Column.size method (pandas-dev#50565)
1 parent 37ff082 commit 2ef976c

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

pandas/core/interchange/column.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,10 @@ def __init__(self, column: pd.Series, allow_copy: bool = True) -> None:
8181
self._col = column
8282
self._allow_copy = allow_copy
8383

84-
def size(self) -> int: # type: ignore[override]
84+
def size(self) -> int:
8585
"""
8686
Size of the column, in elements.
8787
"""
88-
# error: Signature of "size" incompatible with supertype "Column" [override]
8988
return self._col.size
9089

9190
@property

pandas/core/interchange/dataframe_protocol.py

-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ class Column(ABC):
210210
doesn't need its own version or ``__column__`` protocol.
211211
"""
212212

213-
@property
214213
@abstractmethod
215214
def size(self) -> int:
216215
"""

pandas/core/interchange/from_dataframe.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def primitive_column_to_ndarray(col: Column) -> tuple[np.ndarray, Any]:
155155
buffers = col.get_buffers()
156156

157157
data_buff, data_dtype = buffers["data"]
158-
data = buffer_to_ndarray(data_buff, data_dtype, col.offset, col.size)
158+
data = buffer_to_ndarray(data_buff, data_dtype, col.offset, col.size())
159159

160160
data = set_nulls(data, col, buffers["validity"])
161161
return data, buffers
@@ -187,7 +187,7 @@ def categorical_column_to_series(col: Column) -> tuple[pd.Series, Any]:
187187
buffers = col.get_buffers()
188188

189189
codes_buff, codes_dtype = buffers["data"]
190-
codes = buffer_to_ndarray(codes_buff, codes_dtype, col.offset, col.size)
190+
codes = buffer_to_ndarray(codes_buff, codes_dtype, col.offset, col.size())
191191

192192
# Doing module in order to not get ``IndexError`` for
193193
# out-of-bounds sentinel values in `codes`
@@ -244,29 +244,29 @@ def string_column_to_ndarray(col: Column) -> tuple[np.ndarray, Any]:
244244
Endianness.NATIVE,
245245
)
246246
# Specify zero offset as we don't want to chunk the string data
247-
data = buffer_to_ndarray(data_buff, data_dtype, offset=0, length=col.size)
247+
data = buffer_to_ndarray(data_buff, data_dtype, offset=0, length=col.size())
248248

249249
# Retrieve the offsets buffer containing the index offsets demarcating
250250
# the beginning and the ending of each string
251251
offset_buff, offset_dtype = buffers["offsets"]
252252
# Offsets buffer contains start-stop positions of strings in the data buffer,
253-
# meaning that it has more elements than in the data buffer, do `col.size + 1` here
254-
# to pass a proper offsets buffer size
253+
# meaning that it has more elements than in the data buffer, do `col.size() + 1`
254+
# here to pass a proper offsets buffer size
255255
offsets = buffer_to_ndarray(
256-
offset_buff, offset_dtype, col.offset, length=col.size + 1
256+
offset_buff, offset_dtype, col.offset, length=col.size() + 1
257257
)
258258

259259
null_pos = None
260260
if null_kind in (ColumnNullType.USE_BITMASK, ColumnNullType.USE_BYTEMASK):
261261
assert buffers["validity"], "Validity buffers cannot be empty for masks"
262262
valid_buff, valid_dtype = buffers["validity"]
263-
null_pos = buffer_to_ndarray(valid_buff, valid_dtype, col.offset, col.size)
263+
null_pos = buffer_to_ndarray(valid_buff, valid_dtype, col.offset, col.size())
264264
if sentinel_val == 0:
265265
null_pos = ~null_pos
266266

267267
# Assemble the strings from the code units
268-
str_list: list[None | float | str] = [None] * col.size
269-
for i in range(col.size):
268+
str_list: list[None | float | str] = [None] * col.size()
269+
for i in range(col.size()):
270270
# Check for missing values
271271
if null_pos is not None and null_pos[i]:
272272
str_list[i] = np.nan
@@ -349,7 +349,7 @@ def datetime_column_to_ndarray(col: Column) -> tuple[np.ndarray, Any]:
349349
Endianness.NATIVE,
350350
),
351351
col.offset,
352-
col.size,
352+
col.size(),
353353
)
354354

355355
data = parse_datetime_format_str(format_str, data)
@@ -501,7 +501,7 @@ def set_nulls(
501501
elif null_kind in (ColumnNullType.USE_BITMASK, ColumnNullType.USE_BYTEMASK):
502502
assert validity, "Expected to have a validity buffer for the mask"
503503
valid_buff, valid_dtype = validity
504-
null_pos = buffer_to_ndarray(valid_buff, valid_dtype, col.offset, col.size)
504+
null_pos = buffer_to_ndarray(valid_buff, valid_dtype, col.offset, col.size())
505505
if sentinel_val == 0:
506506
null_pos = ~null_pos
507507
elif null_kind in (ColumnNullType.NON_NULLABLE, ColumnNullType.USE_NAN):

0 commit comments

Comments
 (0)