Skip to content

Commit 0f8bece

Browse files
Backport PR #48426 on branch 1.5.x (BUG: Column.size should be a method) (#48465)
Backport PR #48426: BUG: Column.size should be a method Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 045e9e4 commit 0f8bece

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

pandas/core/interchange/column.py

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

84-
@property
8584
def size(self) -> int:
8685
"""
8786
Size of the column, in elements.

pandas/tests/interchange/test_impl.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,14 @@ def test_string():
164164
df = pd.DataFrame({"A": test_str_data})
165165
col = df.__dataframe__().get_column_by_name("A")
166166

167-
assert col.size == 6
167+
assert col.size() == 6
168168
assert col.null_count == 1
169169
assert col.dtype[0] == DtypeKind.STRING
170170
assert col.describe_null == (ColumnNullType.USE_BYTEMASK, 0)
171171

172172
df_sliced = df[1:]
173173
col = df_sliced.__dataframe__().get_column_by_name("A")
174-
assert col.size == 5
174+
assert col.size() == 5
175175
assert col.null_count == 1
176176
assert col.dtype[0] == DtypeKind.STRING
177177
assert col.describe_null == (ColumnNullType.USE_BYTEMASK, 0)
@@ -188,7 +188,7 @@ def test_datetime():
188188
df = pd.DataFrame({"A": [pd.Timestamp("2022-01-01"), pd.NaT]})
189189
col = df.__dataframe__().get_column_by_name("A")
190190

191-
assert col.size == 2
191+
assert col.size() == 2
192192
assert col.null_count == 1
193193
assert col.dtype[0] == DtypeKind.DATETIME
194194
assert col.describe_null == (ColumnNullType.USE_SENTINEL, iNaT)

pandas/tests/interchange/test_spec_conformance.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_only_one_dtype(test_data, df_from_dict):
2727
null_count = dfX.get_column_by_name(column).null_count
2828
assert null_count == 0
2929
assert isinstance(null_count, int)
30-
assert dfX.get_column_by_name(column).size == column_size
30+
assert dfX.get_column_by_name(column).size() == column_size
3131
assert dfX.get_column_by_name(column).offset == 0
3232

3333

@@ -52,7 +52,7 @@ def test_mixed_dtypes(df_from_dict):
5252
colX = dfX.get_column_by_name(column)
5353
assert colX.null_count == 0
5454
assert isinstance(colX.null_count, int)
55-
assert colX.size == 3
55+
assert colX.size() == 3
5656
assert colX.offset == 0
5757

5858
assert colX.dtype[0] == kind
@@ -118,14 +118,14 @@ def test_column_get_chunks(size, n_chunks, df_from_dict):
118118
dfX = df.__dataframe__()
119119
chunks = list(dfX.get_column(0).get_chunks(n_chunks))
120120
assert len(chunks) == n_chunks
121-
assert sum(chunk.size for chunk in chunks) == size
121+
assert sum(chunk.size() for chunk in chunks) == size
122122

123123

124124
def test_get_columns(df_from_dict):
125125
df = df_from_dict({"a": [0, 1], "b": [2.5, 3.5]})
126126
dfX = df.__dataframe__()
127127
for colX in dfX.get_columns():
128-
assert colX.size == 2
128+
assert colX.size() == 2
129129
assert colX.num_chunks() == 1
130130
# for meanings of dtype[0] see the spec; we cannot import the spec here as this
131131
# file is expected to be vendored *anywhere*

0 commit comments

Comments
 (0)