MCPcopy Create free account
hub / github.com/apache/arrow / test_cast_dictionary

Function test_cast_dictionary

python/pyarrow/tests/test_array.py:2088–2109  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2086
2087
2088def 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
2112def test_view():

Callers

nothing calls this directly

Calls 4

arrayMethod · 0.45
dictionaryMethod · 0.45
stringMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected