()
| 2086 | |
| 2087 | |
| 2088 | def test_cast_dictionary(): |
| 2089 | # cast to the value type |
| 2090 | arr = pa.array( |
| 2091 | ["foo", "bar", None], |
| 2092 | type=pa.dictionary(pa.int64(), pa.string()) |
| 2093 | ) |
| 2094 | expected = pa.array(["foo", "bar", None]) |
| 2095 | assert arr.type == pa.dictionary(pa.int64(), pa.string()) |
| 2096 | assert arr.cast(pa.string()) == expected |
| 2097 | |
| 2098 | # cast to a different key type |
| 2099 | for key_type in [pa.int8(), pa.int16(), pa.int32()]: |
| 2100 | typ = pa.dictionary(key_type, pa.string()) |
| 2101 | expected = pa.array( |
| 2102 | ["foo", "bar", None], |
| 2103 | type=pa.dictionary(key_type, pa.string()) |
| 2104 | ) |
| 2105 | assert arr.cast(typ) == expected |
| 2106 | |
| 2107 | # shouldn't crash (ARROW-7077) |
| 2108 | with pytest.raises(pa.ArrowInvalid): |
| 2109 | arr.cast(pa.int32()) |
| 2110 | |
| 2111 | |
| 2112 | def test_view(): |
nothing calls this directly
no test coverage detected