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

Function test_basics_np_required

python/pyarrow/tests/test_scalars.py:110–137  ·  view source on GitHub ↗
(pickle_module)

Source from the content-addressed store, hash-verified

108# fails if numpy is used on the parametrization when not present.
109@pytest.mark.numpy
110def test_basics_np_required(pickle_module):
111 value, ty, klass = np.float16(1.0), pa.float16(), pa.HalfFloatScalar
112 s = pa.scalar(value, type=ty)
113 s.validate()
114 s.validate(full=True)
115 assert isinstance(s, klass)
116 assert s.as_py() == value
117 assert s == pa.scalar(value, type=ty)
118 assert s != value
119 assert s != "else"
120 assert hash(s) == hash(s)
121 assert s.is_valid is True
122 assert s != None # noqa: E711
123
124 s = pa.scalar(None, type=s.type)
125 assert s.is_valid is False
126 assert s.as_py() is None
127 assert s != pa.scalar(value, type=ty)
128
129 # test pickle roundtrip
130 restored = pickle_module.loads(pickle_module.dumps(s))
131 assert s.equals(restored)
132
133 # test that scalars are weak-referenceable
134 wr = weakref.ref(s)
135 assert wr() is not None
136 del s
137 assert wr() is None
138
139
140def test_invalid_scalar():

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