Pandas扩展DType/由Apache Arrow支持的数组
项目描述
弗莱彻
一个库,提供由Apache Arrow支持的Pandas扩展DType/Array的通用实现。它们支持比Pandas原生支持更广泛的类型,并带来了一组不同的约束和行为,这在许多情况下都是有益的。
用法
要在Pandas DataFrame中使用fletcher
,您只需要将数据包装在FletcherChunkedArray
或FletcherContinuousArray
对象中。您的数据可以是pyarrow.Array
、pyarrow.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/
目录中,我们提供了一系列基准测试,用于比较 fletcher
与 pandas
的性能,并确保 fletcher
本身保持高性能。这些基准测试使用 airspeed velocity 编写。在开发基准测试时,您可以使用 asv dev
运行它们(使用 -b <pattern>
仅运行其中一部分),只需运行一次。为了获得实际的基准测试值,您应该使用 asv run --python=same
运行基准测试多次,以获得有意义的平均运行时间。
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分发
构建分发
fletcher-0.7.2.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b646d0a69118ea9f95a62423d139afaa0f404da388bf0106735cfe7d4fb876b6 |
|
MD5 | 2c93f118e37300f71a94934b7f084cf3 |
|
BLAKE2b-256 | 95ceaf8d8b1c6824a68e51c8f920ea491eaf34d1f1e096239130357719a6c78f |
fletcher-0.7.2-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 6f4227b48004dce8f7edd09f658395b30b066f6c7f48439a78e370b5c3a30a2e |
|
MD5 | 0107e272103f23ff2449c9038b1804af |
|
BLAKE2b-256 | d8537be7bf3fda0de3d289bdf2283c8a549d6f0ab3c4a758f65b0ac9a8e08aa9 |