Skip to content

Commit 060ce49

Browse files
authored
TYP: Column.null_count is a Python int (pandas-dev#47804)
1 parent caf261f commit 060ce49

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

pandas/core/exchange/column.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def offset(self) -> int:
9696
return 0
9797

9898
@cache_readonly
99-
def dtype(self):
99+
def dtype(self) -> tuple[DtypeKind, int, str, str]:
100100
dtype = self._col.dtype
101101

102102
if is_categorical_dtype(dtype):
@@ -138,7 +138,7 @@ def _dtype_from_pandasdtype(self, dtype) -> tuple[DtypeKind, int, str, str]:
138138
# Not a NumPy dtype. Check if it's a categorical maybe
139139
raise ValueError(f"Data type {dtype} not supported by exchange protocol")
140140

141-
return (kind, dtype.itemsize * 8, dtype_to_arrow_c_fmt(dtype), dtype.byteorder)
141+
return kind, dtype.itemsize * 8, dtype_to_arrow_c_fmt(dtype), dtype.byteorder
142142

143143
@property
144144
def describe_categorical(self):
@@ -181,10 +181,10 @@ def null_count(self) -> int:
181181
"""
182182
Number of null elements. Should always be known.
183183
"""
184-
return self._col.isna().sum()
184+
return self._col.isna().sum().item()
185185

186186
@property
187-
def metadata(self):
187+
def metadata(self) -> dict[str, pd.Index]:
188188
"""
189189
Store specific metadata of the column.
190190
"""
@@ -196,7 +196,7 @@ def num_chunks(self) -> int:
196196
"""
197197
return 1
198198

199-
def get_chunks(self, n_chunks=None):
199+
def get_chunks(self, n_chunks: int | None = None):
200200
"""
201201
Return an iterator yielding the chunks.
202202
See `DataFrame.get_chunks` for details on ``n_chunks``.

pandas/tests/exchange/test_spec_conformance.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ def test_only_one_dtype(test_data, df_from_dict):
2424

2525
column_size = len(test_data[columns[0]])
2626
for column in columns:
27-
assert dfX.get_column_by_name(column).null_count == 0
27+
null_count = dfX.get_column_by_name(column).null_count
28+
assert null_count == 0
29+
assert isinstance(null_count, int)
2830
assert dfX.get_column_by_name(column).size == column_size
2931
assert dfX.get_column_by_name(column).offset == 0
3032

@@ -49,6 +51,7 @@ def test_mixed_dtypes(df_from_dict):
4951
for column, kind in columns.items():
5052
colX = dfX.get_column_by_name(column)
5153
assert colX.null_count == 0
54+
assert isinstance(colX.null_count, int)
5255
assert colX.size == 3
5356
assert colX.offset == 0
5457

@@ -62,6 +65,7 @@ def test_na_float(df_from_dict):
6265
dfX = df.__dataframe__()
6366
colX = dfX.get_column_by_name("a")
6467
assert colX.null_count == 1
68+
assert isinstance(colX.null_count, int)
6569

6670

6771
def test_noncategorical(df_from_dict):

0 commit comments

Comments
 (0)