Returns the string length when casting the basic dtypes to strings.
(dtype)
| 37 | |
| 38 | |
| 39 | def get_expected_stringlength(dtype): |
| 40 | """Returns the string length when casting the basic dtypes to strings. |
| 41 | """ |
| 42 | if dtype == np.bool_: |
| 43 | return 5 |
| 44 | if dtype.kind in "iu": |
| 45 | if dtype.itemsize == 1: |
| 46 | length = 3 |
| 47 | elif dtype.itemsize == 2: |
| 48 | length = 5 |
| 49 | elif dtype.itemsize == 4: |
| 50 | length = 10 |
| 51 | elif dtype.itemsize == 8: |
| 52 | length = 20 |
| 53 | else: |
| 54 | raise AssertionError(f"did not find expected length for {dtype}") |
| 55 | |
| 56 | if dtype.kind == "i": |
| 57 | length += 1 # adds one character for the sign |
| 58 | |
| 59 | return length |
| 60 | |
| 61 | # Note: Can't do dtype comparison for longdouble on windows |
| 62 | if dtype.char == "g": |
| 63 | return 48 |
| 64 | elif dtype.char == "G": |
| 65 | return 48 * 2 |
| 66 | elif dtype.kind == "f": |
| 67 | return 32 # also for half apparently. |
| 68 | elif dtype.kind == "c": |
| 69 | return 32 * 2 |
| 70 | |
| 71 | raise AssertionError(f"did not find expected length for {dtype}") |
| 72 | |
| 73 | |
| 74 | class Casting(enum.IntEnum): |