()
| 4183 | |
| 4184 | |
| 4185 | def test_variable_dictionary_to_pandas(): |
| 4186 | np.random.seed(12345) |
| 4187 | |
| 4188 | d1 = pa.array(random_strings(100, 32), type='string') |
| 4189 | d2 = pa.array(random_strings(100, 16), type='string') |
| 4190 | d3 = pa.array(random_strings(10000, 10), type='string') |
| 4191 | |
| 4192 | a1 = pa.DictionaryArray.from_arrays( |
| 4193 | np.random.randint(0, len(d1), size=1000, dtype='i4'), |
| 4194 | d1 |
| 4195 | ) |
| 4196 | a2 = pa.DictionaryArray.from_arrays( |
| 4197 | np.random.randint(0, len(d2), size=1000, dtype='i4'), |
| 4198 | d2 |
| 4199 | ) |
| 4200 | |
| 4201 | # With some nulls |
| 4202 | a3 = pa.DictionaryArray.from_arrays( |
| 4203 | np.random.randint(0, len(d3), size=1000, dtype='i4'), d3) |
| 4204 | |
| 4205 | i4 = pa.array( |
| 4206 | np.random.randint(0, len(d3), size=1000, dtype='i4'), |
| 4207 | mask=np.random.rand(1000) < 0.1 |
| 4208 | ) |
| 4209 | a4 = pa.DictionaryArray.from_arrays(i4, d3) |
| 4210 | |
| 4211 | expected_dict = pa.concat_arrays([d1, d2, d3]) |
| 4212 | |
| 4213 | a = pa.chunked_array([a1, a2, a3, a4]) |
| 4214 | a_dense = pa.chunked_array([a1.cast('string'), |
| 4215 | a2.cast('string'), |
| 4216 | a3.cast('string'), |
| 4217 | a4.cast('string')]) |
| 4218 | |
| 4219 | result = a.to_pandas() |
| 4220 | result_dense = a_dense.to_pandas() |
| 4221 | |
| 4222 | assert (result.cat.categories == expected_dict.to_pandas()).all() |
| 4223 | |
| 4224 | expected_dense = result.astype('str') |
| 4225 | expected_dense[result_dense.isnull()] = None |
| 4226 | tm.assert_series_equal(result_dense, expected_dense) |
| 4227 | |
| 4228 | |
| 4229 | def test_dictionary_encoded_nested_to_pandas(): |
nothing calls this directly
no test coverage detected