Skip to content

GH-40376: [Python] Update for NumPy 2.0 ABI change in PyArray_Descr->elsize - #40418

Merged
jorisvandenbossche merged 11 commits into
apache:mainfrom
jorisvandenbossche:gh-40376-numpy-abi
Mar 13, 2024
Merged

GH-40376: [Python] Update for NumPy 2.0 ABI change in PyArray_Descr->elsize#40418
jorisvandenbossche merged 11 commits into
apache:mainfrom
jorisvandenbossche:gh-40376-numpy-abi

Conversation

@jorisvandenbossche

@jorisvandenbosschejorisvandenbossche commented Mar 8, 2024

Copy link
Copy Markdown
Member

Rationale for this change

NumPy 2.0 is changing some ABI, see the issue description and numpy/numpy#25946 for more details.

The changes here should make our code compatible both with current numpy 1.x and future numpy 2.x

…escr->elsize
Co-authored-by: Sebastian Berg <sebastianb@nvidia.com>
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #40376has been automatically assigned in GitHub to PR creator.

@jorisvandenbossche

Copy link
Copy Markdown
MemberAuthor

@seberg we are also using the c_metadata field, which was removed as well.

voidSetDatetimeUnit(NPY_DATETIMEUNIT unit) {
PyAcquireGIL lock;
auto date_dtype = reinterpret_cast<PyArray_DatetimeDTypeMetaData*>(
PyArray_DESCR(reinterpret_cast<PyArrayObject*>(block_arr_.obj()))->c_metadata);
date_dtype->meta.base = unit;
}

@jorisvandenbossche

Copy link
Copy Markdown
MemberAuthor

Should use PyDataType_C_METADATA for that? (with a similar backport for building with 1.x as for elsize)

@seberg

Copy link
Copy Markdown
Contributor

Should use PyDataType_C_METADATA for that? (with a similar backport for building with 1.x as for elsize)

Yes, exactly, thanks!

@jorisvandenbossche

Copy link
Copy Markdown
MemberAuthor

And the same for fields ;)

@jorisvandenbossche

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit -g python

@github-actions

Copy link
Copy Markdown

Revision: 27f15ab

Submitted crossbow builds: ursacomputing/crossbow @ actions-d5247ffd0e

TaskStatus
test-conda-python-3.10GitHub Actions
test-conda-python-3.10-cython2GitHub Actions
test-conda-python-3.10-hdfs-2.9.2GitHub Actions
test-conda-python-3.10-hdfs-3.2.1GitHub Actions
test-conda-python-3.10-pandas-latestGitHub Actions
test-conda-python-3.10-pandas-nightlyGitHub Actions
test-conda-python-3.10-spark-v3.5.0GitHub Actions
test-conda-python-3.10-substraitGitHub Actions
test-conda-python-3.11GitHub Actions
test-conda-python-3.11-dask-latestGitHub Actions
test-conda-python-3.11-dask-upstream_develGitHub Actions
test-conda-python-3.11-hypothesisGitHub Actions
test-conda-python-3.11-pandas-upstream_develGitHub Actions
test-conda-python-3.11-spark-masterGitHub Actions
test-conda-python-3.12GitHub Actions
test-conda-python-3.8GitHub Actions
test-conda-python-3.8-pandas-1.0GitHub Actions
test-conda-python-3.8-spark-v3.5.0GitHub Actions
test-conda-python-3.9GitHub Actions
test-conda-python-3.9-pandas-latestGitHub Actions
test-cuda-pythonGitHub Actions
test-debian-11-python-3-amd64Azure
test-debian-11-python-3-i386GitHub Actions
test-fedora-39-python-3Azure
test-ubuntu-20.04-python-3Azure
test-ubuntu-22.04-python-3GitHub Actions

@sebergseberg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, the changes look good to me from the NumPy side. Maybe we should add a way to get datetime metadata more directly some time (and if fields/names would be real functions we would have more freedom to modify it, but that isn't a downstream code change now at least :)).

Comment threadpython/pyarrow/src/arrow/python/numpy_to_arrow.cc
@github-actionsgithub-actionsBot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Mar 8, 2024
@github-actionsgithub-actionsBot added awaiting change review Awaiting change review awaiting changes Awaiting changes and removed awaiting changes Awaiting changes awaiting change review Awaiting change review labels Mar 8, 2024
@kou

kou commented Mar 10, 2024

Copy link
Copy Markdown
Member

@github-actions crossbow submit -g wheel

@github-actions

This comment was marked as outdated.

@kou

kou commented Mar 11, 2024

Copy link
Copy Markdown
Member

It seems that wheel-manylinux failures and wheel-windows failures are related to this.

@jorisvandenbossche

Copy link
Copy Markdown
MemberAuthor

Yes, those are related, but it's because it is not yet picking up the latest nightly numpy wheel to build against (the changes in this PR require numpy changes of a few days ago).
How do you ensure the docker image doesn't use a cached layer?

@jorisvandenbossche

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@jorisvandenbossche

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit wheel-windows-cp312-amd64

@github-actions

Copy link
Copy Markdown

Revision: 74caa26

Submitted crossbow builds: ursacomputing/crossbow @ actions-e37c72b24e

TaskStatus
wheel-windows-cp312-amd64GitHub Actions

@jorisvandenbossche

Copy link
Copy Markdown
MemberAuthor

OK, my last commit adding some extra prints to our cmake set up at least confirms that in this case it is using an older numpy:

-- Found NumPy version: 2.0.0.dev0+git20240203.5c34c87
-- NumPy include dir: C:/Python312/Lib/site-packages/numpy/_core/include

(from beginning of February, which matches with the time when those images were last updated #39622)

Will then try again to force rebuilding them here in this PR (it's not clear to me how that can be done generally)

@jorisvandenbossche

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit wheel-windows-cp312-amd64

@github-actions

Copy link
Copy Markdown

Revision: 49df2c5

Submitted crossbow builds: ursacomputing/crossbow @ actions-d87170315f

TaskStatus
wheel-windows-cp312-amd64GitHub Actions

@jorisvandenbossche

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit wheel-windows-cp312-amd64

@github-actions

Copy link
Copy Markdown

Revision: 0d97bf8

Submitted crossbow builds: ursacomputing/crossbow @ actions-7909cb5614

TaskStatus
wheel-windows-cp312-amd64GitHub Actions

@jorisvandenbossche

jorisvandenbossche commented Mar 12, 2024

Copy link
Copy Markdown
MemberAuthor

OK, my last commit did succeed in ensuring we weren't accidentally using the cached images, and now it was building with against numpy 2.0.0b1 as shown by cmake, and now the windows build did succeed! (well, still red but now that's the known test failure on windows, which will be fixed with rebasing)

So the actual code changes are all good here. Now I only need to figure out how to ensure we rebuild the cached images properly (instead of just not using the cache as I did in the last commit, which I don't want to merge to main)

@jorisvandenbossche

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit wheel-windows-cp312-amd64

@github-actions

Copy link
Copy Markdown

Revision: c3e18d1

Submitted crossbow builds: ursacomputing/crossbow @ actions-5ccdad511a

TaskStatus
wheel-windows-cp312-amd64GitHub Actions

@jorisvandenbossche

Copy link
Copy Markdown
MemberAuthor

@github-actions crossbow submit test-conda-python-3.10-pandas-nightly test-conda-python-3.11-pandas-upstream_devel

@github-actions

Copy link
Copy Markdown

Revision: c3e18d1

Submitted crossbow builds: ursacomputing/crossbow @ actions-5525cfe7b2

TaskStatus
test-conda-python-3.10-pandas-nightlyGitHub Actions
test-conda-python-3.11-pandas-upstream_develGitHub Actions

kou
kou approved these changes Mar 12, 2024

@koukou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

@github-actionsgithub-actionsBot added awaiting merge Awaiting merge and removed awaiting change review Awaiting change review labels Mar 12, 2024
@jorisvandenbossche

jorisvandenbossche commented Mar 13, 2024

Copy link
Copy Markdown
MemberAuthor

Remaining failures are now actual (and known) test failures (the pandas nightly is being fixed by #40429)

@jorisvandenbossche
jorisvandenbossche merged commit a421314 into apache:mainMar 13, 2024
@jorisvandenbosschejorisvandenbossche removed the awaiting merge Awaiting merge label Mar 13, 2024
@jorisvandenbossche
jorisvandenbossche deleted the gh-40376-numpy-abi branch March 13, 2024 07:56
@seberg

Copy link
Copy Markdown
Contributor

Thanks for working on this, I wish rebuilding from scratch was less tedious.

@jorisvandenbossche

Copy link
Copy Markdown
MemberAuthor

The tediousness was mostly because of our own building infrastructure, not because of numpy ;) Thanks for the help!

@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 7 benchmarking runs that have been run so far on merge-commit a421314.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 5 possible false positives for unstable benchmarks that are known to sometimes produce them.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@jorisvandenbossche@seberg@kou