當前位置: 首頁>>代碼示例>>Python>>正文


Python pyarrow.uint8方法代碼示例

本文整理匯總了Python中pyarrow.uint8方法的典型用法代碼示例。如果您正苦於以下問題:Python pyarrow.uint8方法的具體用法?Python pyarrow.uint8怎麽用?Python pyarrow.uint8使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyarrow的用法示例。


在下文中一共展示了pyarrow.uint8方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_get_array_null_bitmap_as_byte_array

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import uint8 [as 別名]
def test_get_array_null_bitmap_as_byte_array(self):
    array = pa.array([], type=pa.int32())
    null_masks = array_util.GetArrayNullBitmapAsByteArray(array)
    self.assertTrue(null_masks.equals(pa.array([], type=pa.uint8())))

    array = pa.array([1, 2, None, 3, None], type=pa.int32())
    null_masks = array_util.GetArrayNullBitmapAsByteArray(array)
    self.assertTrue(
        null_masks.equals(pa.array([0, 0, 1, 0, 1], type=pa.uint8())))

    array = pa.array([1, 2, 3])
    null_masks = array_util.GetArrayNullBitmapAsByteArray(array)
    self.assertTrue(null_masks.equals(pa.array([0, 0, 0], type=pa.uint8())))

    array = pa.array([None, None, None], type=pa.int32())
    null_masks = array_util.GetArrayNullBitmapAsByteArray(array)
    self.assertTrue(null_masks.equals(pa.array([1, 1, 1], type=pa.uint8())))
    # Demonstrate that the returned array can be converted to a numpy boolean
    # array w/o copying
    np.testing.assert_equal(
        np.array([True, True, True]), null_masks.to_numpy().view(np.bool)) 
開發者ID:tensorflow,項目名稱:tfx-bsl,代碼行數:23,代碼來源:array_util_test.py

示例2: _get_numeric_byte_size_test_cases

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import uint8 [as 別名]
def _get_numeric_byte_size_test_cases():
  result = []
  for array_type, sizeof in [
      (pa.int8(), 1),
      (pa.uint8(), 1),
      (pa.int16(), 2),
      (pa.uint16(), 2),
      (pa.int32(), 4),
      (pa.uint32(), 4),
      (pa.int64(), 8),
      (pa.uint64(), 8),
      (pa.float32(), 4),
      (pa.float64(), 8),
  ]:
    result.append(
        dict(
            testcase_name=str(array_type),
            array=pa.array(range(9), type=array_type),
            slice_offset=2,
            slice_length=3,
            expected_size=(_all_false_null_bitmap_size(2) + sizeof * 9),
            expected_sliced_size=(_all_false_null_bitmap_size(1) + sizeof * 3)))
  return result 
開發者ID:tensorflow,項目名稱:tfx-bsl,代碼行數:25,代碼來源:array_util_test.py

示例3: _get_numba_typ_from_pa_typ

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import uint8 [as 別名]
def _get_numba_typ_from_pa_typ(pa_typ):
    import pyarrow as pa
    _typ_map = {
        # boolean
        pa.bool_(): types.bool_,
        # signed int types
        pa.int8(): types.int8,
        pa.int16(): types.int16,
        pa.int32(): types.int32,
        pa.int64(): types.int64,
        # unsigned int types
        pa.uint8(): types.uint8,
        pa.uint16(): types.uint16,
        pa.uint32(): types.uint32,
        pa.uint64(): types.uint64,
        # float types (TODO: float16?)
        pa.float32(): types.float32,
        pa.float64(): types.float64,
        # String
        pa.string(): string_type,
        # date
        pa.date32(): types.NPDatetime('ns'),
        pa.date64(): types.NPDatetime('ns'),
        # time (TODO: time32, time64, ...)
        pa.timestamp('ns'): types.NPDatetime('ns'),
        pa.timestamp('us'): types.NPDatetime('ns'),
        pa.timestamp('ms'): types.NPDatetime('ns'),
        pa.timestamp('s'): types.NPDatetime('ns'),
    }
    if pa_typ not in _typ_map:
        raise ValueError("Arrow data type {} not supported yet".format(pa_typ))
    return _typ_map[pa_typ] 
開發者ID:IntelPython,項目名稱:sdc,代碼行數:34,代碼來源:parquet_pio.py

示例4: _dtype_to_arrow_type

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import uint8 [as 別名]
def _dtype_to_arrow_type(dtype: np.dtype) -> pyarrow.DataType:
    if dtype == np.int8:
        return pyarrow.int8()
    elif dtype == np.int16:
        return pyarrow.int16()
    elif dtype == np.int32:
        return pyarrow.int32()
    elif dtype == np.int64:
        return pyarrow.int64()
    elif dtype == np.uint8:
        return pyarrow.uint8()
    elif dtype == np.uint16:
        return pyarrow.uint16()
    elif dtype == np.uint32:
        return pyarrow.uint32()
    elif dtype == np.uint64:
        return pyarrow.uint64()
    elif dtype == np.float16:
        return pyarrow.float16()
    elif dtype == np.float32:
        return pyarrow.float32()
    elif dtype == np.float64:
        return pyarrow.float64()
    elif dtype.kind == "M":
        # [2019-09-17] Pandas only allows "ns" unit -- as in, datetime64[ns]
        # https://github.com/pandas-dev/pandas/issues/7307#issuecomment-224180563
        assert dtype.str.endswith("[ns]")
        return pyarrow.timestamp(unit="ns", tz=None)
    elif dtype == np.object_:
        return pyarrow.string()
    else:
        raise RuntimeError("Unhandled dtype %r" % dtype) 
開發者ID:CJWorkbench,項目名稱:cjworkbench,代碼行數:34,代碼來源:types.py

示例5: test_dataframe_uint8_column

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import uint8 [as 別名]
def test_dataframe_uint8_column(self):
        assert_arrow_table_equals(
            dataframe_to_arrow_table(
                pd.DataFrame({"A": [1, 2, 3, 253]}, dtype=np.uint8),
                [Column("A", ColumnType.NUMBER("{:,d}"))],
                self.path,
            ),
            arrow_table(
                {"A": pyarrow.array([1, 2, 3, 253], type=pyarrow.uint8())},
                [atypes.Column("A", atypes.ColumnType.Number("{:,d}"))],
            ),
        ) 
開發者ID:CJWorkbench,項目名稱:cjworkbench,代碼行數:14,代碼來源:test_types.py

示例6: test_arrow_uint8_column

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import uint8 [as 別名]
def test_arrow_uint8_column(self):
        dataframe, columns = arrow_table_to_dataframe(
            arrow_table(
                {"A": pyarrow.array([1, 2, 3, 253], type=pyarrow.uint8())},
                columns=[atypes.Column("A", atypes.ColumnType.Number("{:,d}"))],
            )
        )
        assert_frame_equal(
            dataframe, pd.DataFrame({"A": [1, 2, 3, 253]}, dtype=np.uint8)
        )
        self.assertEqual(columns, [Column("A", ColumnType.NUMBER("{:,d}"))]) 
開發者ID:CJWorkbench,項目名稱:cjworkbench,代碼行數:13,代碼來源:test_types.py


注:本文中的pyarrow.uint8方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。