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

Function test_dictionary_from_numpy

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

Source from the content-addressed store, hash-verified

989
990@pytest.mark.numpy
991def test_dictionary_from_numpy():
992 indices = np.repeat([0, 1, 2], 2)
993 dictionary = np.array(['foo', 'bar', 'baz'], dtype=object)
994 mask = np.array([False, False, True, False, False, False])
995
996 d1 = pa.DictionaryArray.from_arrays(indices, dictionary)
997 d2 = pa.DictionaryArray.from_arrays(indices, dictionary, mask=mask)
998
999 assert d1.indices.to_pylist() == indices.tolist()
1000 assert d1.indices.to_pylist() == indices.tolist()
1001 assert d1.dictionary.to_pylist() == dictionary.tolist()
1002 assert d2.dictionary.to_pylist() == dictionary.tolist()
1003
1004 for i in range(len(indices)):
1005 assert d1[i].as_py() == dictionary[indices[i]]
1006
1007 if mask[i]:
1008 assert d2[i].as_py() is None
1009 else:
1010 assert d2[i].as_py() == dictionary[indices[i]]
1011
1012
1013@pytest.mark.numpy

Callers

nothing calls this directly

Calls 3

lenFunction · 0.85
as_pyMethod · 0.80
arrayMethod · 0.45

Tested by

no test coverage detected