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

Function test_timestamp

python/pyarrow/tests/test_scalars.py:413–437  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

411
412@pytest.mark.pandas
413def test_timestamp():
414 import pandas as pd
415 arr = pd.date_range('2000-01-01 12:34:56', periods=10).values
416
417 units = ['ns', 'us', 'ms', 's']
418
419 for i, unit in enumerate(units):
420 dtype = f'datetime64[{unit}]'
421 arrow_arr = pa.Array.from_pandas(arr.astype(dtype))
422 expected = pd.Timestamp('2000-01-01 12:34:56')
423
424 assert arrow_arr[0].as_py() == expected
425 assert arrow_arr[0].value * 1000**i == expected.value
426
427 tz = 'America/New_York'
428 arrow_type = pa.timestamp(unit, tz=tz)
429
430 dtype = f'datetime64[{unit}]'
431 arrow_arr = pa.Array.from_pandas(arr.astype(dtype), type=arrow_type)
432 expected = (pd.Timestamp('2000-01-01 12:34:56')
433 .tz_localize('utc')
434 .tz_convert(tz))
435
436 assert arrow_arr[0].as_py() == expected
437 assert arrow_arr[0].value * 1000**i == expected.value
438
439
440@pytest.mark.nopandas

Callers

nothing calls this directly

Calls 2

as_pyMethod · 0.80
TimestampMethod · 0.45

Tested by

no test coverage detected