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

Function test_array_from_scalar

python/pyarrow/tests/test_array.py:377–429  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

375
376
377def test_array_from_scalar():
378 pytz = pytest.importorskip("pytz")
379
380 today = datetime.date.today()
381 now = datetime.datetime.now()
382 now_utc = now.replace(tzinfo=pytz.utc)
383 now_with_tz = now_utc.astimezone(pytz.timezone('US/Eastern'))
384 oneday = datetime.timedelta(days=1)
385
386 cases = [
387 (None, 1, pa.array([None])),
388 (None, 10, pa.nulls(10)),
389 (-1, 3, pa.array([-1, -1, -1], type=pa.int64())),
390 (2.71, 2, pa.array([2.71, 2.71], type=pa.float64())),
391 ("string", 4, pa.array(["string"] * 4)),
392 (
393 pa.scalar(8, type=pa.uint8()),
394 17,
395 pa.array([8] * 17, type=pa.uint8())
396 ),
397 (pa.scalar(None), 3, pa.array([None, None, None])),
398 (pa.scalar(True), 11, pa.array([True] * 11)),
399 (today, 2, pa.array([today] * 2)),
400 (now, 10, pa.array([now] * 10)),
401 (
402 now_with_tz,
403 2,
404 pa.array(
405 [now_utc] * 2,
406 type=pa.timestamp('us', tz=pytz.timezone('US/Eastern'))
407 )
408 ),
409 (now.time(), 9, pa.array([now.time()] * 9)),
410 (oneday, 4, pa.array([oneday] * 4)),
411 (False, 9, pa.array([False] * 9)),
412 ([1, 2], 2, pa.array([[1, 2], [1, 2]])),
413 (
414 pa.scalar([-1, 3], type=pa.large_list(pa.int8())),
415 5,
416 pa.array([[-1, 3]] * 5, type=pa.large_list(pa.int8()))
417 ),
418 ({'a': 1, 'b': 2}, 3, pa.array([{'a': 1, 'b': 2}] * 3))
419 ]
420
421 for value, size, expected in cases:
422 arr = pa.repeat(value, size)
423 assert len(arr) == size
424 assert arr.type.equals(expected.type)
425 assert arr.equals(expected)
426 if expected.type == pa.null():
427 assert arr.null_count == size
428 else:
429 assert arr.null_count == 0
430
431
432def test_array_from_dictionary_scalar():

Callers

nothing calls this directly

Calls 6

lenFunction · 0.85
timezoneMethod · 0.80
timeMethod · 0.80
equalsMethod · 0.80
arrayMethod · 0.45
scalarMethod · 0.45

Tested by

no test coverage detected