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

Function test_table_unify_dictionaries

python/pyarrow/tests/test_table.py:1978–2012  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1976
1977
1978def test_table_unify_dictionaries():
1979 batch1 = pa.record_batch([
1980 pa.array(["foo", "bar", None, "foo"]).dictionary_encode(),
1981 pa.array([123, 456, 456, 789]).dictionary_encode(),
1982 pa.array([True, False, None, None])], names=['a', 'b', 'c'])
1983 batch2 = pa.record_batch([
1984 pa.array(["quux", "foo", None, "quux"]).dictionary_encode(),
1985 pa.array([456, 789, 789, None]).dictionary_encode(),
1986 pa.array([False, None, None, True])], names=['a', 'b', 'c'])
1987
1988 table = pa.Table.from_batches([batch1, batch2])
1989 table = table.replace_schema_metadata({b"key1": b"value1"})
1990 assert table.column(0).chunk(0).dictionary.equals(
1991 pa.array(["foo", "bar"]))
1992 assert table.column(0).chunk(1).dictionary.equals(
1993 pa.array(["quux", "foo"]))
1994 assert table.column(1).chunk(0).dictionary.equals(
1995 pa.array([123, 456, 789]))
1996 assert table.column(1).chunk(1).dictionary.equals(
1997 pa.array([456, 789]))
1998
1999 table = table.unify_dictionaries(pa.default_memory_pool())
2000 expected_dict_0 = pa.array(["foo", "bar", "quux"])
2001 expected_dict_1 = pa.array([123, 456, 789])
2002 assert table.column(0).chunk(0).dictionary.equals(expected_dict_0)
2003 assert table.column(0).chunk(1).dictionary.equals(expected_dict_0)
2004 assert table.column(1).chunk(0).dictionary.equals(expected_dict_1)
2005 assert table.column(1).chunk(1).dictionary.equals(expected_dict_1)
2006
2007 assert table.to_pydict() == {
2008 'a': ["foo", "bar", None, "foo", "quux", "foo", None, "quux"],
2009 'b': [123, 456, 456, 789, 456, 789, 789, None],
2010 'c': [True, False, None, None, False, None, None, True],
2011 }
2012 assert table.schema.metadata == {b"key1": b"value1"}
2013
2014
2015def test_table_maps_as_pydicts():

Callers

nothing calls this directly

Calls 3

equalsMethod · 0.80
arrayMethod · 0.45
columnMethod · 0.45

Tested by

no test coverage detected