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

Function test_dictionary_from_pandas

python/pyarrow/tests/test_pandas.py:4262–4283  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4260
4261
4262def test_dictionary_from_pandas():
4263 cat = pd.Categorical(['a', 'b', 'a'])
4264 expected_type = pa.dictionary(
4265 pa.int8(),
4266 pa.large_string() if _pandas_api.uses_string_dtype() else pa.string()
4267 )
4268
4269 result = pa.array(cat)
4270 assert result.to_pylist() == ['a', 'b', 'a']
4271 assert result.type.equals(expected_type)
4272
4273 # with missing values in categorical
4274 cat = pd.Categorical(['a', 'b', None, 'a'])
4275
4276 result = pa.array(cat)
4277 assert result.to_pylist() == ['a', 'b', None, 'a']
4278 assert result.type.equals(expected_type)
4279
4280 # with additional mask
4281 result = pa.array(cat, mask=np.array([False, False, False, True]))
4282 assert result.to_pylist() == ['a', 'b', None, None]
4283 assert result.type.equals(expected_type)
4284
4285
4286def test_dictionary_from_pandas_specified_type():

Callers

nothing calls this directly

Calls 4

equalsMethod · 0.80
dictionaryMethod · 0.45
stringMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected