()
| 4248 | |
| 4249 | |
| 4250 | def test_variable_dictionary_to_pandas(): |
| 4251 | np.random.seed(12345) |
| 4252 | |
| 4253 | d1 = pa.array(random_strings(100, 32), type='string') |
| 4254 | d2 = pa.array(random_strings(100, 16), type='string') |
| 4255 | d3 = pa.array(random_strings(10000, 10), type='string') |
| 4256 | |
| 4257 | a1 = pa.DictionaryArray.from_arrays( |
| 4258 | np.random.randint(0, len(d1), size=1000, dtype='i4'), |
| 4259 | d1 |
| 4260 | ) |
| 4261 | a2 = pa.DictionaryArray.from_arrays( |
| 4262 | np.random.randint(0, len(d2), size=1000, dtype='i4'), |
| 4263 | d2 |
| 4264 | ) |
| 4265 | |
| 4266 | # With some nulls |
| 4267 | a3 = pa.DictionaryArray.from_arrays( |
| 4268 | np.random.randint(0, len(d3), size=1000, dtype='i4'), d3) |
| 4269 | |
| 4270 | i4 = pa.array( |
| 4271 | np.random.randint(0, len(d3), size=1000, dtype='i4'), |
| 4272 | mask=np.random.rand(1000) < 0.1 |
| 4273 | ) |
| 4274 | a4 = pa.DictionaryArray.from_arrays(i4, d3) |
| 4275 | |
| 4276 | expected_dict = pa.concat_arrays([d1, d2, d3]) |
| 4277 | |
| 4278 | a = pa.chunked_array([a1, a2, a3, a4]) |
| 4279 | a_dense = pa.chunked_array([a1.cast('string'), |
| 4280 | a2.cast('string'), |
| 4281 | a3.cast('string'), |
| 4282 | a4.cast('string')]) |
| 4283 | |
| 4284 | result = a.to_pandas() |
| 4285 | result_dense = a_dense.to_pandas() |
| 4286 | |
| 4287 | assert (result.cat.categories == expected_dict.to_pandas()).all() |
| 4288 | |
| 4289 | expected_dense = result.astype('str') |
| 4290 | expected_dense[result_dense.isnull()] = None |
| 4291 | tm.assert_series_equal(result_dense, expected_dense) |
| 4292 | |
| 4293 | |
| 4294 | def test_dictionary_encoded_nested_to_pandas(): |
nothing calls this directly
no test coverage detected