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

Function test_basics_np_required

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

Source from the content-addressed store, hash-verified

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