()
| 4203 | |
| 4204 | |
| 4205 | def test_variable_dictionary_to_pandas(): |
| 4206 | np.random.seed(12345) |
| 4207 | |
| 4208 | d1 = pa.array(random_strings(100, 32), type='string') |
| 4209 | d2 = pa.array(random_strings(100, 16), type='string') |
| 4210 | d3 = pa.array(random_strings(10000, 10), type='string') |
| 4211 | |
| 4212 | a1 = pa.DictionaryArray.from_arrays( |
| 4213 | np.random.randint(0, len(d1), size=1000, dtype='i4'), |
| 4214 | d1 |
| 4215 | ) |
| 4216 | a2 = pa.DictionaryArray.from_arrays( |
| 4217 | np.random.randint(0, len(d2), size=1000, dtype='i4'), |
| 4218 | d2 |
| 4219 | ) |
| 4220 | |
| 4221 | # With some nulls |
| 4222 | a3 = pa.DictionaryArray.from_arrays( |
| 4223 | np.random.randint(0, len(d3), size=1000, dtype='i4'), d3) |
| 4224 | |
| 4225 | i4 = pa.array( |
| 4226 | np.random.randint(0, len(d3), size=1000, dtype='i4'), |
| 4227 | mask=np.random.rand(1000) < 0.1 |
| 4228 | ) |
| 4229 | a4 = pa.DictionaryArray.from_arrays(i4, d3) |
| 4230 | |
| 4231 | expected_dict = pa.concat_arrays([d1, d2, d3]) |
| 4232 | |
| 4233 | a = pa.chunked_array([a1, a2, a3, a4]) |
| 4234 | a_dense = pa.chunked_array([a1.cast('string'), |
| 4235 | a2.cast('string'), |
| 4236 | a3.cast('string'), |
| 4237 | a4.cast('string')]) |
| 4238 | |
| 4239 | result = a.to_pandas() |
| 4240 | result_dense = a_dense.to_pandas() |
| 4241 | |
| 4242 | assert (result.cat.categories == expected_dict.to_pandas()).all() |
| 4243 | |
| 4244 | expected_dense = result.astype('str') |
| 4245 | expected_dense[result_dense.isnull()] = None |
| 4246 | tm.assert_series_equal(result_dense, expected_dense) |
| 4247 | |
| 4248 | |
| 4249 | def test_dictionary_encoded_nested_to_pandas(): |
nothing calls this directly
no test coverage detected