Skip to content

Commit cc94e57

Browse files
committed
Add comments explaing magic dtype numbers
Signed-off-by: Vasily Litvinov <[email protected]>
1 parent f030d9f commit cc94e57

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

pandas/tests/exchange/test_spec_conformance.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@ def test_only_one_dtype(test_data, df_from_dict):
3232
def test_mixed_dtypes(df_from_dict):
3333
df = df_from_dict(
3434
{
35-
"a": [1, 2, 3],
36-
"b": [3, 4, 5],
37-
"c": [1.5, 2.5, 3.5],
38-
"d": [9, 10, 11],
39-
"e": [True, False, True],
40-
"f": ["a", "", "c"],
35+
"a": [1, 2, 3], # dtype kind INT = 0
36+
"b": [3, 4, 5], # dtype kind INT = 0
37+
"c": [1.5, 2.5, 3.5], # dtype kind FLOAT = 2
38+
"d": [9, 10, 11], # dtype kind INT = 0
39+
"e": [True, False, True], # dtype kind BOOLEAN = 20
40+
"f": ["a", "", "c"], # dtype kind STRING = 21
4141
}
4242
)
4343
dfX = df.__dataframe__()
44+
# for meanings of dtype[0] see the spec; we cannot import the spec here as this
45+
# file is expected to be vendored *anywhere*;
46+
# values for dtype[0] are explained above
4447
columns = {"a": 0, "b": 0, "c": 2, "d": 0, "e": 20, "f": 21}
4548

4649
for column, kind in columns.items():
@@ -120,8 +123,10 @@ def test_get_columns(df_from_dict):
120123
for colX in dfX.get_columns():
121124
assert colX.size == 2
122125
assert colX.num_chunks() == 1
123-
assert dfX.get_column(0).dtype[0] == 0
124-
assert dfX.get_column(1).dtype[0] == 2
126+
# for meanings of dtype[0] see the spec; we cannot import the spec here as this
127+
# file is expected to be vendored *anywhere*
128+
assert dfX.get_column(0).dtype[0] == 0 # INT
129+
assert dfX.get_column(1).dtype[0] == 2 # FLOAT
125130

126131

127132
def test_buffer(df_from_dict):
@@ -137,7 +142,9 @@ def test_buffer(df_from_dict):
137142
assert dataBuf.ptr != 0
138143
device, _ = dataBuf.__dlpack_device__()
139144

140-
assert dataDtype[0] == 0
145+
# for meanings of dtype[0] see the spec; we cannot import the spec here as this
146+
# file is expected to be vendored *anywhere*
147+
assert dataDtype[0] == 0 # INT
141148

142149
if device == 1: # CPU-only as we're going to directly read memory here
143150
bitwidth = dataDtype[1]

0 commit comments

Comments
 (0)