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

Function test_basics

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

Source from the content-addressed store, hash-verified

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