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

Function test_timestamp

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

as_pyMethod · 0.80
TimestampMethod · 0.45

Tested by

no test coverage detected