|
| 1 | +import locale |
| 2 | + |
1 | 3 | import numpy as np
|
2 | 4 | import pytest
|
3 | 5 |
|
| 6 | +from pandas.compat import ( |
| 7 | + is_platform_windows, |
| 8 | + np_version_under1p19, |
| 9 | +) |
| 10 | + |
4 | 11 | import pandas as pd
|
5 | 12 | import pandas._testing as tm
|
6 | 13 | from pandas.core.arrays import FloatingArray
|
@@ -40,6 +47,33 @@ def test_floating_array_constructor():
|
40 | 47 | FloatingArray(values)
|
41 | 48 |
|
42 | 49 |
|
| 50 | +def test_floating_array_disallows_float16(request): |
| 51 | + # GH#44715 |
| 52 | + arr = np.array([1, 2], dtype=np.float16) |
| 53 | + mask = np.array([False, False]) |
| 54 | + |
| 55 | + msg = "FloatingArray does not support np.float16 dtype" |
| 56 | + with pytest.raises(TypeError, match=msg): |
| 57 | + FloatingArray(arr, mask) |
| 58 | + |
| 59 | + if not np_version_under1p19: |
| 60 | + # Troubleshoot |
| 61 | + # https://github.com/numpy/numpy/issues/20512#issuecomment-985807740 |
| 62 | + lowered = np.core._type_aliases.english_lower("Float16") |
| 63 | + assert lowered == "float16", lowered |
| 64 | + |
| 65 | + if np_version_under1p19 or ( |
| 66 | + locale.getlocale()[0] != "en_US" and not is_platform_windows() |
| 67 | + ): |
| 68 | + # the locale condition may need to be refined; this fails on |
| 69 | + # the CI in the ZH_CN build |
| 70 | + mark = pytest.mark.xfail(reason="numpy does not raise on np.dtype('Float16')") |
| 71 | + request.node.add_marker(mark) |
| 72 | + |
| 73 | + with pytest.raises(TypeError, match="data type 'Float16' not understood"): |
| 74 | + pd.array([1.0, 2.0], dtype="Float16") |
| 75 | + |
| 76 | + |
43 | 77 | def test_floating_array_constructor_copy():
|
44 | 78 | values = np.array([1, 2, 3, 4], dtype="float64")
|
45 | 79 | mask = np.array([False, False, False, True], dtype="bool")
|
|
0 commit comments