跳转到主要内容

Pandas扩展DType/由Apache Arrow支持的数组

项目描述

弗莱彻

CI Code style: black Binder

一个库,提供由Apache Arrow支持的Pandas扩展DType/Array的通用实现。它们支持比Pandas原生支持更广泛的类型,并带来了一组不同的约束和行为,这在许多情况下都是有益的。

用法

要在Pandas DataFrame中使用fletcher,您只需要将数据包装在FletcherChunkedArrayFletcherContinuousArray对象中。您的数据可以是pyarrow.Arraypyarrow.ChunkedArray或可以传递给pyarrow.array(…)的类型。

import fletcher as fr
import pandas as pd

df = pd.DataFrame({
    'str_chunked': fr.FletcherChunkedArray(['a', 'b', 'c']),
    'str_continuous': fr.FletcherContinuousArray(['a', 'b', 'c']),
})

df.info()

# <class 'pandas.core.frame.DataFrame'>
# RangeIndex: 3 entries, 0 to 2
# Data columns (total 2 columns):
#  #   Column          Non-Null Count  Dtype                      
# ---  ------          --------------  -----                      
#  0   str_chunked     3 non-null      fletcher_chunked[string]   
#  1   str_continuous  3 non-null      fletcher_continuous[string]
# dtypes: fletcher_chunked[string](1), fletcher_continuous[string](1)
# memory usage: 166.0 bytes

开发

虽然您可以在基于pip的环境中使用fletcher,但我们强烈建议使用基于conda的开发设置,并使用来自conda-forge的包。

# Create the conda environment with all necessary dependencies
conda env create

# Activate the newly created environment
conda activate fletcher

# Install fletcher into the current environment
python -m pip install -e . --no-build-isolation --no-use-pep517

# Run the unit tests (you should do this several times during development)
py.test -nauto

# Install pre-commit hooks
# These will then be automatically run on every commit and ensure that files
# are black formatted, have no flake8 issues and mypy checks the type consistency.
pre-commit install

代码格式化使用black完成。这应该保持一切的一致风格,格式化通过pre-commit钩子自动调整。

以开发模式使用pandas

要测试和开发针对pandas的master或您的本地修复,您可以使用以下命令安装pandas的开发版本

git clone https://github.com/pandas-dev/pandas
cd pandas

# Install additional pandas dependencies
conda install -y cython

# Build and install pandas
python setup.py build_ext --inplace -j 4
python -m pip install -e . --no-build-isolation --no-use-pep517

这将链接到pandas开发版本到您的fletcher conda环境。如果您更改了pandas中的任何Python代码,它将直接反映在您的环境中。如果您更改了pandas中的任何Cython代码,您需要重新执行python setup.py build_ext --inplace -j 4

使用(py)arrow夜间版

要测试和开发针对Apache Arrow的最新开发版本(pyarrow),您可以从中安装它arrow-nightlies conda通道

conda install -c arrow-nightlies arrow-cpp pyarrow

基准测试

benchmarks/ 目录中,我们提供了一系列基准测试,用于比较 fletcherpandas 的性能,并确保 fletcher 本身保持高性能。这些基准测试使用 airspeed velocity 编写。在开发基准测试时,您可以使用 asv dev 运行它们(使用 -b <pattern> 仅运行其中一部分),只需运行一次。为了获得实际的基准测试值,您应该使用 asv run --python=same 运行基准测试多次,以获得有意义的平均运行时间。

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分发

fletcher-0.7.2.tar.gz (72.7 kB 查看哈希值)

上传时间

构建分发

fletcher-0.7.2-py3-none-any.whl (49.8 kB 查看哈希值)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面