Skip to content

Backport PR #48426 on branch 1.5.x (BUG: Column.size should be a method) #48465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pandas/core/interchange/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def __init__(self, column: pd.Series, allow_copy: bool = True) -> None:
self._col = column
self._allow_copy = allow_copy

@property
def size(self) -> int:
"""
Size of the column, in elements.
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/interchange/test_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ def test_string():
df = pd.DataFrame({"A": test_str_data})
col = df.__dataframe__().get_column_by_name("A")

assert col.size == 6
assert col.size() == 6
assert col.null_count == 1
assert col.dtype[0] == DtypeKind.STRING
assert col.describe_null == (ColumnNullType.USE_BYTEMASK, 0)

df_sliced = df[1:]
col = df_sliced.__dataframe__().get_column_by_name("A")
assert col.size == 5
assert col.size() == 5
assert col.null_count == 1
assert col.dtype[0] == DtypeKind.STRING
assert col.describe_null == (ColumnNullType.USE_BYTEMASK, 0)
Expand All @@ -188,7 +188,7 @@ def test_datetime():
df = pd.DataFrame({"A": [pd.Timestamp("2022-01-01"), pd.NaT]})
col = df.__dataframe__().get_column_by_name("A")

assert col.size == 2
assert col.size() == 2
assert col.null_count == 1
assert col.dtype[0] == DtypeKind.DATETIME
assert col.describe_null == (ColumnNullType.USE_SENTINEL, iNaT)
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/interchange/test_spec_conformance.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_only_one_dtype(test_data, df_from_dict):
null_count = dfX.get_column_by_name(column).null_count
assert null_count == 0
assert isinstance(null_count, int)
assert dfX.get_column_by_name(column).size == column_size
assert dfX.get_column_by_name(column).size() == column_size
assert dfX.get_column_by_name(column).offset == 0


Expand All @@ -52,7 +52,7 @@ def test_mixed_dtypes(df_from_dict):
colX = dfX.get_column_by_name(column)
assert colX.null_count == 0
assert isinstance(colX.null_count, int)
assert colX.size == 3
assert colX.size() == 3
assert colX.offset == 0

assert colX.dtype[0] == kind
Expand Down Expand Up @@ -118,14 +118,14 @@ def test_column_get_chunks(size, n_chunks, df_from_dict):
dfX = df.__dataframe__()
chunks = list(dfX.get_column(0).get_chunks(n_chunks))
assert len(chunks) == n_chunks
assert sum(chunk.size for chunk in chunks) == size
assert sum(chunk.size() for chunk in chunks) == size


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