def test_read_year_month_nano_interval(tmpdir): """ARROW-15783: Verify to_pandas works for interval types. Interval types require static structures to be enabled. This test verifies that they are when no other library functions are invoked. """ mdn_interval_type = pa.month_day_nano_interval() schema = pa.schema([pa.field('nums', mdn_interval_type)]) path = tmpdir.join('file.arrow').strpath with pa.OSFile(path, 'wb') as sink: with pa.ipc.new_file(sink, schema) as writer: interval_array = pa.array([(1, 2, 3)], type=mdn_interval_type) batch = pa.record_batch([interval_array], schema) writer.write(batch) invoke_script('read_record_batch.py', path)
def test_is_temporal_date_time_timestamp(): date_types = [pa.date32(), pa.date64()] time_types = [pa.time32('s'), pa.time64('ns')] timestamp_types = [pa.timestamp('ms')] duration_types = [pa.duration('ms')] interval_types = [pa.month_day_nano_interval()] for case in (date_types + time_types + timestamp_types + duration_types + interval_types): assert types.is_temporal(case) for case in date_types: assert types.is_date(case) assert not types.is_time(case) assert not types.is_timestamp(case) assert not types.is_duration(case) assert not types.is_interval(case) for case in time_types: assert types.is_time(case) assert not types.is_date(case) assert not types.is_timestamp(case) assert not types.is_duration(case) assert not types.is_interval(case) for case in timestamp_types: assert types.is_timestamp(case) assert not types.is_date(case) assert not types.is_time(case) assert not types.is_duration(case) assert not types.is_interval(case) for case in duration_types: assert types.is_duration(case) assert not types.is_date(case) assert not types.is_time(case) assert not types.is_timestamp(case) assert not types.is_interval(case) for case in interval_types: assert types.is_interval(case) assert not types.is_date(case) assert not types.is_time(case) assert not types.is_timestamp(case) assert not types.is_temporal(pa.int32())
def test_type_for_alias(): cases = [ ('i1', pa.int8()), ('int8', pa.int8()), ('i2', pa.int16()), ('int16', pa.int16()), ('i4', pa.int32()), ('int32', pa.int32()), ('i8', pa.int64()), ('int64', pa.int64()), ('u1', pa.uint8()), ('uint8', pa.uint8()), ('u2', pa.uint16()), ('uint16', pa.uint16()), ('u4', pa.uint32()), ('uint32', pa.uint32()), ('u8', pa.uint64()), ('uint64', pa.uint64()), ('f4', pa.float32()), ('float32', pa.float32()), ('f8', pa.float64()), ('float64', pa.float64()), ('date32', pa.date32()), ('date64', pa.date64()), ('string', pa.string()), ('str', pa.string()), ('binary', pa.binary()), ('time32[s]', pa.time32('s')), ('time32[ms]', pa.time32('ms')), ('time64[us]', pa.time64('us')), ('time64[ns]', pa.time64('ns')), ('timestamp[s]', pa.timestamp('s')), ('timestamp[ms]', pa.timestamp('ms')), ('timestamp[us]', pa.timestamp('us')), ('timestamp[ns]', pa.timestamp('ns')), ('duration[s]', pa.duration('s')), ('duration[ms]', pa.duration('ms')), ('duration[us]', pa.duration('us')), ('duration[ns]', pa.duration('ns')), ('month_day_nano_interval', pa.month_day_nano_interval()), ] for val, expected in cases: assert pa.type_for_alias(val) == expected
pa.time64('us'), pa.time64('ns')]) if tzst and zoneinfo: timezones = st.one_of(st.none(), tzst.timezones(), st.timezones()) elif tzst: timezones = st.one_of(st.none(), tzst.timezones()) elif zoneinfo: timezones = st.one_of(st.none(), st.timezones()) else: timezones = st.none() timestamp_types = st.builds(pa.timestamp, unit=st.sampled_from(['s', 'ms', 'us', 'ns']), tz=timezones) duration_types = st.builds(pa.duration, st.sampled_from(['s', 'ms', 'us', 'ns'])) interval_types = st.just(pa.month_day_nano_interval()) temporal_types = st.one_of(date_types, time_types, timestamp_types, duration_types, interval_types) primitive_types = st.one_of(null_type, bool_type, numeric_types, temporal_types, binary_like_types) metadata = st.dictionaries(st.text(), st.text()) @st.composite def fields(draw, type_strategy=primitive_types): name = draw(custom_text) typ = draw(type_strategy) if pa.types.is_null(typ): nullable = True
scale=st.integers(min_value=1, max_value=76)) numeric_types = st.one_of(integer_types, floating_types, decimal128_type, decimal256_type) date_types = st.sampled_from([pa.date32(), pa.date64()]) time_types = st.sampled_from( [pa.time32('s'), pa.time32('ms'), pa.time64('us'), pa.time64('ns')]) timestamp_types = st.builds(pa.timestamp, unit=st.sampled_from(['s', 'ms', 'us', 'ns']), tz=tzst.timezones()) duration_types = st.builds(pa.duration, st.sampled_from(['s', 'ms', 'us', 'ns'])) interval_types = st.sampled_from(pa.month_day_nano_interval()) temporal_types = st.one_of(date_types, time_types, timestamp_types, duration_types, interval_types) primitive_types = st.one_of(null_type, bool_type, numeric_types, temporal_types, binary_like_types) metadata = st.dictionaries(st.text(), st.text()) @st.composite def fields(draw, type_strategy=primitive_types): name = draw(custom_text) typ = draw(type_strategy) if pa.types.is_null(typ): nullable = True