| 989 | |
| 990 | @pytest.mark.numpy |
| 991 | def 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 |