Skip to content

refactor: Optimize DataFrame Reconstruction & Update Docs for Linux ARM64 Release #795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Check out more detailed usage and examples [here](https://sfu-db.github.io/conne
pip install connectorx
```

_For AArch64 or ARM64 Linux users, `connectorx==0.4.3 & above` is only available for distributions using `glibc 2.35` and above. Specifically, the re-release for this architecture was tested on Ubuntu 22.04. For older distributions, the latest version available is `connectorx==0.2.3` due to dependency limitations._

Check out [here](https://sfu-db.github.io/connector-x/install.html#build-from-source-code) to see how to build python wheel from source.

# Performance
Expand Down
12 changes: 8 additions & 4 deletions connectorx-python/connectorx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,23 +459,27 @@ def reconstruct_pandas(df_infos: _DataframeInfos) -> pd.DataFrame:
pd.core.internals.make_block(block_data, placement=binfo.cids)
)
elif binfo.dt == 1: # IntegerArray
integer_array = pd.core.arrays.IntegerArray._from_sequence(block_data[0])
integer_array._mask = block_data[1]
blocks.append(
pd.core.internals.make_block(
pd.core.arrays.IntegerArray(block_data[0], block_data[1]),
integer_array,
placement=binfo.cids[0],
)
)
elif binfo.dt == 2: # BooleanArray
bool_array = pd.core.arrays.BooleanArray._from_sequence(block_data[0])
Copy link
Contributor

@wangxiaoying wangxiaoying Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand from the pandas source code (_from_sequence, coerce_to_array), it seems we will have an extra mask array constructed by this _from_sequence step, which will then be discarded and replaced by our mask array like in this example:
image

And also it seems to directly call the constructor of the BooleanArray anyway. I'm wondering why this _from_sequence approach is still faster than the old BooleanArray(data, mask) approach as it seems to only include the overhead of an additional mask construction. I'm I missing something here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for verifying this, you're right that for BooleanArray & IntegerArray, the additional overhead of mask construction would mean that the from_sequence approach would be slower — I seem to have missed that out when benchmarking the different array types.

I will reflect this accordingly!

bool_array._mask = block_data[1]
blocks.append(
pd.core.internals.make_block(
pd.core.arrays.BooleanArray(block_data[0], block_data[1]),
bool_array,
placement=binfo.cids[0],
)
)
elif binfo.dt == 3: # DatetimeArray
blocks.append(
pd.core.internals.make_block(
pd.core.arrays.DatetimeArray(block_data), placement=binfo.cids
pd.core.arrays.DatetimeArray._from_sequence(block_data), placement=binfo.cids
)
)
else:
Expand All @@ -484,7 +488,7 @@ def reconstruct_pandas(df_infos: _DataframeInfos) -> pd.DataFrame:
block_manager = pd.core.internals.BlockManager(
blocks, [pd.Index(headers), pd.RangeIndex(start=0, stop=nrows, step=1)]
)
df = pd.DataFrame(block_manager)
df = pd.DataFrame._from_mgr(block_manager, axes=[headers, range(nrows)])
return df


Expand Down
4 changes: 4 additions & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ The easiest way to install ConnectorX is using pip, with the following command:
pip install connectorx
```

```{note}
For AArch64 or ARM64 Linux users, `connectorx==0.4.3 & above` is only available for distributions using `glibc 2.35` and above. Specifically, the re-release for this architecture was tested on Ubuntu 22.04. For older distributions, the latest version available is `connectorx==0.2.3` due to dependency limitations.
```

### Build from source code

* Step 0: Install tools.
Expand Down
Loading