Skip to content

Commit a407339

Browse files
committed
Format exchange tests by black
Signed-off-by: Vasily Litvinov <vasilij.n.litvinov@intel.com>
1 parent 9d74d44 commit a407339

File tree

2 files changed

+51
-23
lines changed

2 files changed

+51
-23
lines changed

pandas/tests/api/conftest.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
import pandas as pd
33
from pandas.api.exchange.implementation import _from_dataframe
44

5-
@pytest.fixture(scope='package')
5+
6+
@pytest.fixture(scope="package")
67
def df_from_dict():
78
def maker(dct, is_categorical=False):
89
df = pd.DataFrame(dct)
9-
return df.astype('category') if is_categorical else df
10+
return df.astype("category") if is_categorical else df
11+
1012
return maker
1113

12-
@pytest.fixture(scope='package')
14+
15+
@pytest.fixture(scope="package")
1316
def df_from_xchg():
1417
def maker(xchg):
1518
return _from_dataframe(xchg)
19+
1620
return maker

pandas/tests/api/test_protocol.py

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
import math
33
import ctypes
44

5-
@pytest.mark.parametrize("test_data",
6-
[
7-
{"a": ["foo", "bar"],
8-
"b": ["baz", "qux"]},
9-
{"a": [1.5, 2.5, 3.5], "b": [9.2, 10.5, 11.8]},
10-
{"A": [1, 2, 3, 4], "B": [1, 2, 3, 4]}
11-
],
12-
ids=["str_data", "float_data", "int_data"])
5+
6+
@pytest.mark.parametrize(
7+
"test_data",
8+
[
9+
{"a": ["foo", "bar"], "b": ["baz", "qux"]},
10+
{"a": [1.5, 2.5, 3.5], "b": [9.2, 10.5, 11.8]},
11+
{"A": [1, 2, 3, 4], "B": [1, 2, 3, 4]},
12+
],
13+
ids=["str_data", "float_data", "int_data"],
14+
)
1315
def test_only_one_dtype(test_data, df_from_dict):
1416
columns = list(test_data.keys())
1517
df = df_from_dict(test_data)
@@ -23,10 +25,16 @@ def test_only_one_dtype(test_data, df_from_dict):
2325

2426

2527
def test_float_int(df_from_dict):
26-
df = df_from_dict({"a": [1, 2, 3], "b": [3, 4, 5],
27-
"c": [1.5, 2.5, 3.5], "d": [9, 10, 11],
28-
"e": [True, False, True],
29-
"f": ["a", "", "c"]})
28+
df = df_from_dict(
29+
{
30+
"a": [1, 2, 3],
31+
"b": [3, 4, 5],
32+
"c": [1.5, 2.5, 3.5],
33+
"d": [9, 10, 11],
34+
"e": [True, False, True],
35+
"f": ["a", "", "c"],
36+
}
37+
)
3038
dfX = df.__dataframe__()
3139
columns = {"a": 0, "b": 0, "c": 2, "d": 0, "e": 20, "f": 21}
3240

@@ -47,15 +55,20 @@ def test_na_float(df_from_dict):
4755
colX = dfX.get_column_by_name("a")
4856
assert colX.null_count == 1
4957

58+
5059
def test_noncategorical(df_from_dict):
5160
df = df_from_dict({"a": [1, 2, 3]})
5261
dfX = df.__dataframe__()
5362
colX = dfX.get_column_by_name("a")
5463
with pytest.raises(TypeError):
5564
colX.describe_categorical
5665

66+
5767
def test_categorical(df_from_dict):
58-
df = df_from_dict({"weekday": ["Mon", "Tue", "Mon", "Wed", "Mon", "Thu", "Fri", "Sat", "Sun"]}, is_categorical=True)
68+
df = df_from_dict(
69+
{"weekday": ["Mon", "Tue", "Mon", "Wed", "Mon", "Thu", "Fri", "Sat", "Sun"]},
70+
is_categorical=True,
71+
)
5972

6073
colX = df.__dataframe__().get_column_by_name("weekday")
6174
is_ordered, is_dictionary, _ = colX.describe_categorical
@@ -64,14 +77,20 @@ def test_categorical(df_from_dict):
6477

6578

6679
def test_dataframe(df_from_dict):
67-
df = df_from_dict({"x": [True, True, False], "y": [1, 2, 0], "z": [9.2, 10.5, 11.8]})
80+
df = df_from_dict(
81+
{"x": [True, True, False], "y": [1, 2, 0], "z": [9.2, 10.5, 11.8]}
82+
)
6883
dfX = df.__dataframe__()
6984

7085
assert dfX.num_columns() == 3
7186
assert dfX.num_rows() == 3
7287
assert dfX.num_chunks() == 1
7388
assert dfX.column_names() == ["x", "y", "z"]
74-
assert dfX.select_columns((0, 2)).column_names() == dfX.select_columns_by_name(("x", "z")).column_names()
89+
assert (
90+
dfX.select_columns((0, 2)).column_names()
91+
== dfX.select_columns_by_name(("x", "z")).column_names()
92+
)
93+
7594

7695
@pytest.mark.parametrize(["size", "n_chunks"], [(10, 3), (12, 3), (12, 5)])
7796
def test_df_get_chunks(size, n_chunks, df_from_dict):
@@ -81,6 +100,7 @@ def test_df_get_chunks(size, n_chunks, df_from_dict):
81100
assert len(chunks) == n_chunks
82101
assert sum(chunk.num_rows() for chunk in chunks) == size
83102

103+
84104
@pytest.mark.parametrize(["size", "n_chunks"], [(10, 3), (12, 3), (12, 5)])
85105
def test_column_get_chunks(size, n_chunks, df_from_dict):
86106
df = df_from_dict({"x": list(range(size))})
@@ -89,6 +109,7 @@ def test_column_get_chunks(size, n_chunks, df_from_dict):
89109
assert len(chunks) == n_chunks
90110
assert sum(chunk.size for chunk in chunks) == size
91111

112+
92113
def test_get_columns(df_from_dict):
93114
df = df_from_dict({"a": [0, 1], "b": [2.5, 3.5]})
94115
dfX = df.__dataframe__()
@@ -98,6 +119,7 @@ def test_get_columns(df_from_dict):
98119
assert dfX.get_column(0).dtype[0] == 0
99120
assert dfX.get_column(1).dtype[0] == 2
100121

122+
101123
def test_buffer(df_from_dict):
102124
arr = [0, 1, -1]
103125
df = df_from_dict({"a": arr})
@@ -113,12 +135,14 @@ def test_buffer(df_from_dict):
113135

114136
assert dataDtype[0] == 0
115137

116-
if device == 1: # CPU-only as we're going to directly read memory here
138+
if device == 1: # CPU-only as we're going to directly read memory here
117139
bitwidth = dataDtype[1]
118-
ctype = {8: ctypes.c_int8,
119-
16: ctypes.c_int16,
120-
32: ctypes.c_int32,
121-
64: ctypes.c_int64}[bitwidth]
140+
ctype = {
141+
8: ctypes.c_int8,
142+
16: ctypes.c_int16,
143+
32: ctypes.c_int32,
144+
64: ctypes.c_int64,
145+
}[bitwidth]
122146

123147
for idx, truth in enumerate(arr):
124148
val = ctype.from_address(dataBuf.ptr + idx * (bitwidth // 8)).value

0 commit comments

Comments
 (0)