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

Function test_basics

python/pyarrow/tests/test_scalars.py:76–102  ·  view source on GitHub ↗
(value, ty, klass, pickle_module)

Source from the content-addressed store, hash-verified

74 ([('a', 1), ('b', 2)], pa.map_(pa.string(), pa.int8()), pa.MapScalar),
75])
76def test_basics(value, ty, klass, pickle_module):
77 s = pa.scalar(value, type=ty)
78 s.validate()
79 s.validate(full=True)
80 assert isinstance(s, klass)
81 assert s.as_py() == value
82 assert s == pa.scalar(value, type=ty)
83 assert s != value
84 assert s != "else"
85 assert hash(s) == hash(s)
86 assert s.is_valid is True
87 assert s != None # noqa: E711
88
89 s = pa.scalar(None, type=s.type)
90 assert s.is_valid is False
91 assert s.as_py() is None
92 assert s != pa.scalar(value, type=ty)
93
94 # test pickle roundtrip
95 restored = pickle_module.loads(pickle_module.dumps(s))
96 assert s.equals(restored)
97
98 # test that scalars are weak-referenceable
99 wr = weakref.ref(s)
100 assert wr() is not None
101 del s
102 assert wr() is None
103
104
105# This test is a copy of test_basics but only for float16 (HalfFloatScalar)

Callers

nothing calls this directly

Calls 7

hashFunction · 0.85
as_pyMethod · 0.80
loadsMethod · 0.80
dumpsMethod · 0.80
equalsMethod · 0.80
scalarMethod · 0.45
validateMethod · 0.45

Tested by

no test coverage detected