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

Function test_nested_with_timestamp_tz

python/pyarrow/tests/test_pandas.py:4095–4140  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4093
4094
4095def test_nested_with_timestamp_tz():
4096 # ARROW-7723
4097 ts = pd.Timestamp.now()
4098 ts_dt = ts.to_pydatetime()
4099
4100 # XXX: Ensure that this data does not get promoted to nanoseconds (and thus
4101 # integers) to preserve behavior in 0.15.1
4102 for unit in ['s', 'ms', 'us']:
4103 if unit in ['s', 'ms']:
4104 # This is used for verifying timezone conversion to micros are not
4105 # important
4106 def truncate(x): return x.replace(microsecond=0)
4107 else:
4108 def truncate(x): return x
4109 arr = pa.array([ts], type=pa.timestamp(unit))
4110 arr2 = pa.array([ts], type=pa.timestamp(unit, tz='America/New_York'))
4111
4112 arr3 = pa.StructArray.from_arrays([arr, arr], ['start', 'stop'])
4113 arr4 = pa.StructArray.from_arrays([arr2, arr2], ['start', 'stop'])
4114
4115 result = arr3.to_pandas()
4116 assert isinstance(result[0]['start'], datetime)
4117 assert result[0]['start'].tzinfo is None
4118 assert isinstance(result[0]['stop'], datetime)
4119 assert result[0]['stop'].tzinfo is None
4120
4121 result = arr4.to_pandas()
4122 assert isinstance(result[0]['start'], datetime)
4123 assert result[0]['start'].tzinfo is not None
4124 utc_dt = result[0]['start'].astimezone(timezone.utc)
4125 assert truncate(utc_dt).replace(tzinfo=None) == truncate(ts_dt)
4126 assert isinstance(result[0]['stop'], datetime)
4127 assert result[0]['stop'].tzinfo is not None
4128
4129 # same conversion for table
4130 result = pa.table({'a': arr3}).to_pandas()
4131 assert isinstance(result['a'][0]['start'], datetime)
4132 assert result['a'][0]['start'].tzinfo is None
4133 assert isinstance(result['a'][0]['stop'], datetime)
4134 assert result['a'][0]['stop'].tzinfo is None
4135
4136 result = pa.table({'a': arr4}).to_pandas()
4137 assert isinstance(result['a'][0]['start'], datetime)
4138 assert result['a'][0]['start'].tzinfo is not None
4139 assert isinstance(result['a'][0]['stop'], datetime)
4140 assert result['a'][0]['stop'].tzinfo is not None
4141
4142
4143# ----------------------------------------------------------------------

Callers

nothing calls this directly

Calls 2

truncateFunction · 0.85
arrayMethod · 0.45

Tested by

no test coverage detected