10
10
11
11
np = pytest .importorskip ("numpy" )
12
12
13
+ if env .WIN :
14
+ # Windows does not have these (see e.g. #1908). But who knows, maybe later?
15
+ np_float128_or_none = getattr (np , "float128" , None )
16
+ np_complex256_or_none = getattr (np , "complex256" , None )
17
+ else :
18
+ np_float128_or_none = np .float128
19
+ np_complex256_or_none = np .complex256
20
+
13
21
14
22
@pytest .mark .parametrize (
15
23
("cpp_name" , "expected_fmts" , "np_array_dtype" ),
26
34
("std::uint64_t" , ["Q" ], np .uint64 ),
27
35
("float" , ["f" ], np .float32 ),
28
36
("double" , ["d" ], np .float64 ),
29
- ("long double" , ["g" , "d" ], np . float128 ),
37
+ ("long double" , ["g" , "d" ], np_float128_or_none ),
30
38
("std::complex<float>" , ["Zf" ], np .complex64 ),
31
39
("std::complex<double>" , ["Zd" ], np .complex128 ),
32
- ("std::complex<long double>" , ["Zg" , "Zd" ], np . complex256 ),
40
+ ("std::complex<long double>" , ["Zg" , "Zd" ], np_complex256_or_none ),
33
41
],
34
42
)
35
43
def test_format_descriptor_format (cpp_name , expected_fmts , np_array_dtype ):
@@ -39,15 +47,16 @@ def test_format_descriptor_format(cpp_name, expected_fmts, np_array_dtype):
39
47
# Everything below just documents long-standing inconsistencies.
40
48
# See also: https://github.com/pybind/pybind11/issues/1908
41
49
42
- # py::format_descriptor<> vs np.array:
43
- na = np .array ([], dtype = np_array_dtype )
44
- bi = m .get_buffer_info (na )
45
- if fmt == "q" :
46
- assert bi .format in ["q" , "l" ]
47
- elif fmt == "Q" :
48
- assert bi .format in ["Q" , "L" ]
49
- else :
50
- assert bi .format == fmt
50
+ if np_array_dtype is not None :
51
+ # py::format_descriptor<> vs np.array:
52
+ na = np .array ([], dtype = np_array_dtype )
53
+ bi = m .get_buffer_info (na )
54
+ if fmt == "q" :
55
+ assert bi .format in ["q" , "l" ]
56
+ elif fmt == "Q" :
57
+ assert bi .format in ["Q" , "L" ]
58
+ else :
59
+ assert bi .format == fmt
51
60
52
61
# py::format_descriptor<> vs np.format_parser():
53
62
fmtp = fmt [1 :] if fmt .startswith ("Z" ) else fmt
0 commit comments