Skip to content

fix: avoid deprecated unitless operations for NumPy 2.5 compatibility#17589

Merged
parthea merged 1 commit into
mainfrom
fix-build-db-dtypes
Jun 30, 2026
Merged

fix: avoid deprecated unitless operations for NumPy 2.5 compatibility#17589
parthea merged 1 commit into
mainfrom
fix-build-db-dtypes

Conversation

@parthea

@parthea parthea commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

As per https://numpy.org/devdocs/release/2.5.0-notes.html, using the generic unit in numpy.timedelta64 is deprecated since this can lead to unexpected behavior such as non-transitive comparison.

This should fix the following errors (since warnings are treated as errors when testing)

2026-06-26T22:39:25.0532625Z ==================================== ERRORS ====================================
2026-06-26T22:39:25.0533378Z __________________ ERROR collecting tests/unit/test_arrow.py ___________________
2026-06-26T22:39:25.0533991Z tests/unit/test_arrow.py:24: in <module>
2026-06-26T22:39:25.0534413Z     import db_dtypes
2026-06-26T22:39:25.0534767Z db_dtypes/__init__.py:30: in <module>
2026-06-26T22:39:25.0535219Z     from db_dtypes import core
2026-06-26T22:39:25.0536530Z db_dtypes/core.py:46: in <module>
2026-06-26T22:39:25.0537237Z     class BaseDatetimeArray(pandas_backports.OpsMixin, _mixins.NDArrayBackedExtensionArray):
2026-06-26T22:39:25.0537974Z db_dtypes/core.py:51: in BaseDatetimeArray
2026-06-26T22:39:25.0538450Z     _internal_fill_value = numpy.datetime64("NaT")
2026-06-26T22:39:25.0538897Z                            ^^^^^^^^^^^^^^^^^^^^^^^
2026-06-26T22:39:25.0540172Z E   DeprecationWarning: The 'generic' unit for NumPy timedelta is deprecated, and will raise an error in the future. This includes implicit conversion of bare integers (e.g. `+ 1`).Please use a specific unit instead.
2026-06-26T22:39:25.0541561Z ___________________ ERROR collecting tests/unit/test_date.py ___________________
2026-06-26T22:39:25.0542129Z tests/unit/test_date.py:25: in <module>
2026-06-26T22:39:25.0542500Z     import db_dtypes
2026-06-26T22:39:25.0542818Z db_dtypes/__init__.py:30: in <module>
2026-06-26T22:39:25.0543197Z     from db_dtypes import core
2026-06-26T22:39:25.0543563Z db_dtypes/core.py:46: in <module>
2026-06-26T22:39:25.0544218Z     class BaseDatetimeArray(pandas_backports.OpsMixin, _mixins.NDArrayBackedExtensionArray):
2026-06-26T22:39:25.0545002Z db_dtypes/core.py:51: in BaseDatetimeArray
2026-06-26T22:39:25.0545474Z     _internal_fill_value = numpy.datetime64("NaT")
2026-06-26T22:39:25.0546102Z                            ^^^^^^^^^^^^^^^^^^^^^^^
2026-06-26T22:39:25.0547340Z E   DeprecationWarning: The 'generic' unit for NumPy timedelta is deprecated, and will raise an error in the future. This includes implicit conversion of bare integers (e.g. `+ 1`).Please use a specific unit instead.
2026-06-26T22:39:25.0548760Z ___________________ ERROR collecting tests/unit/test_json.py ___________________
2026-06-26T22:39:25.0549293Z tests/unit/test_json.py:22: in <module>
2026-06-26T22:39:25.0549664Z     import db_dtypes
2026-06-26T22:39:25.0549980Z db_dtypes/__init__.py:30: in <module>
2026-06-26T22:39:25.0550363Z     from db_dtypes import core
2026-06-26T22:39:25.0550720Z db_dtypes/core.py:46: in <module>
2026-06-26T22:39:25.0551394Z     class BaseDatetimeArray(pandas_backports.OpsMixin, _mixins.NDArrayBackedExtensionArray):
2026-06-26T22:39:25.0552080Z db_dtypes/core.py:51: in BaseDatetimeArray
2026-06-26T22:39:25.0552528Z     _internal_fill_value = numpy.datetime64("NaT")
2026-06-26T22:39:25.0552958Z                            ^^^^^^^^^^^^^^^^^^^^^^^
2026-06-26T22:39:25.0554405Z E   DeprecationWarning: The 'generic' unit for NumPy timedelta is deprecated, and will raise an error in the future. This includes implicit conversion of bare integers (e.g. `+ 1`).Please use a specific unit instead.
2026-06-26T22:39:25.0555740Z _____________ ERROR collecting tests/unit/test_pandas_backports.py _____________
2026-06-26T22:39:25.0556539Z tests/unit/test_pandas_backports.py:18: in <module>
2026-06-26T22:39:25.0557049Z     import db_dtypes.pandas_backports as pandas_backports
2026-06-26T22:39:25.0557498Z db_dtypes/__init__.py:30: in <module>
2026-06-26T22:39:25.0557873Z     from db_dtypes import core
2026-06-26T22:39:25.0558234Z db_dtypes/core.py:46: in <module>
2026-06-26T22:39:25.0558863Z     class BaseDatetimeArray(pandas_backports.OpsMixin, _mixins.NDArrayBackedExtensionArray):
2026-06-26T22:39:25.0559525Z db_dtypes/core.py:51: in BaseDatetimeArray
2026-06-26T22:39:25.0559977Z     _internal_fill_value = numpy.datetime64("NaT")
2026-06-26T22:39:25.0560384Z                            ^^^^^^^^^^^^^^^^^^^^^^^
2026-06-26T22:39:25.0561598Z E   DeprecationWarning: The 'generic' unit for NumPy timedelta is deprecated, and will raise an error in the future. This includes implicit conversion of bare integers (e.g. `+ 1`).Please use a specific unit instead.
2026-06-26T22:39:25.0562922Z ___________________ ERROR collecting tests/unit/test_time.py ___________________
2026-06-26T22:39:25.0563453Z tests/unit/test_time.py:22: in <module>
2026-06-26T22:39:25.0563840Z     import db_dtypes  # noqa
2026-06-26T22:39:25.0564160Z     ^^^^^^^^^^^^^^^^
2026-06-26T22:39:25.0564460Z db_dtypes/__init__.py:30: in <module>
2026-06-26T22:39:25.0565066Z     from db_dtypes import core
2026-06-26T22:39:25.0565406Z db_dtypes/core.py:46: in <module>
2026-06-26T22:39:25.0566176Z     class BaseDatetimeArray(pandas_backports.OpsMixin, _mixins.NDArrayBackedExtensionArray):
2026-06-26T22:39:25.0566858Z db_dtypes/core.py:51: in BaseDatetimeArray
2026-06-26T22:39:25.0567282Z     _internal_fill_value = numpy.datetime64("NaT")
2026-06-26T22:39:25.0567695Z                            ^^^^^^^^^^^^^^^^^^^^^^^
2026-06-26T22:39:25.0568851Z E   DeprecationWarning: The 'generic' unit for NumPy timedelta is deprecated, and will raise an error in the future. This includes implicit conversion of bare integers (e.g. `+ 1`).Please use a specific unit instead.
2026-06-26T22:39:25.0570116Z =========================== short test summary info ============================
2026-06-26T22:39:25.0571523Z ERROR tests/unit/test_arrow.py - DeprecationWarning: The 'generic' unit for NumPy timedelta is deprecated, and will raise an error in the future. This includes implicit conversion of bare integers (e.g. `+ 1`).Please use a specific unit instead.
2026-06-26T22:39:25.0573906Z ERROR tests/unit/test_date.py - DeprecationWarning: The 'generic' unit for NumPy timedelta is deprecated, and will raise an error in the future. This includes implicit conversion of bare integers (e.g. `+ 1`).Please use a specific unit instead.
2026-06-26T22:39:25.0576196Z ERROR tests/unit/test_json.py - DeprecationWarning: The 'generic' unit for NumPy timedelta is deprecated, and will raise an error in the future. This includes implicit conversion of bare integers (e.g. `+ 1`).Please use a specific unit instead.
2026-06-26T22:39:25.0578467Z ERROR tests/unit/test_pandas_backports.py - DeprecationWarning: The 'generic' unit for NumPy timedelta is deprecated, and will raise an error in the future. This includes implicit conversion of bare integers (e.g. `+ 1`).Please use a specific unit instead.
2026-06-26T22:39:25.0580766Z ERROR tests/unit/test_time.py - DeprecationWarning: The 'generic' unit for NumPy timedelta is deprecated, and will raise an error in the future. This includes implicit conversion of bare integers (e.g. `+ 1`).Please use a specific unit instead.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates db-dtypes to explicitly specify the nanosecond ("ns") unit for numpy.datetime64 initializations and dynamically aligns the epoch's dtype with the target array's dtype during timedelta calculations. The review feedback suggests simplifying the epoch alignment in both astype and __add__ by directly casting _NPEPOCH to the target array's dtype instead of manually extracting the datetime unit.

Comment thread packages/db-dtypes/db_dtypes/__init__.py Outdated
Comment thread packages/db-dtypes/db_dtypes/__init__.py Outdated
@parthea parthea force-pushed the fix-build-db-dtypes branch from e72a566 to edd3bf9 Compare June 29, 2026 17:45
@parthea

parthea commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates db-dtypes to explicitly specify the "ns" unit for numpy.datetime64 epoch and NaT initializations, and casts the epoch to match the array's dtype during subtraction. The feedback highlights potential unit mismatches: hardcoding "ns" for _internal_fill_value in the base class BaseDatetimeArray can cause issues for subclasses like DateArray (which uses "D"), and returning "ns" NaT in _datetime may also conflict with DateArray's underlying storage unit.

Comment thread packages/db-dtypes/db_dtypes/core.py Outdated
Comment thread packages/db-dtypes/db_dtypes/__init__.py Outdated
@parthea parthea force-pushed the fix-build-db-dtypes branch 3 times, most recently from 2e543ac to 086356e Compare June 29, 2026 20:00
@parthea

parthea commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@parthea parthea marked this pull request as ready for review June 29, 2026 20:01
@parthea parthea requested review from a team as code owners June 29, 2026 20:01
@parthea parthea requested review from tswast and removed request for a team June 29, 2026 20:01

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request addresses numpy unit mismatches by dynamically determining the resolution unit for _internal_fill_value and matching the epoch's dtype with the array's dtype during subtraction. Additionally, it updates coverage settings and adds a unit test for the fallback behavior of _internal_fill_value. The review feedback highlights a potential regression in astype where casting the epoch could result in returning day-resolution deltas instead of the requested nanosecond-resolution deltas, and suggests using the local ndarray variable in _internal_fill_value to avoid redundant attribute lookups.

Comment thread packages/db-dtypes/db_dtypes/__init__.py Outdated
Comment thread packages/db-dtypes/db_dtypes/core.py Outdated
@parthea parthea assigned parthea and unassigned tswast Jun 30, 2026
@parthea parthea marked this pull request as draft June 30, 2026 13:33
@parthea parthea force-pushed the fix-build-db-dtypes branch 6 times, most recently from 3e889e2 to 315a93e Compare June 30, 2026 15:14
@parthea parthea force-pushed the fix-build-db-dtypes branch from 315a93e to d7c437f Compare June 30, 2026 15:26
@parthea parthea marked this pull request as ready for review June 30, 2026 15:28
@parthea parthea assigned tswast and unassigned parthea Jun 30, 2026
@parthea parthea merged commit d0b2abc into main Jun 30, 2026
30 checks passed
@parthea parthea deleted the fix-build-db-dtypes branch June 30, 2026 15:54
This was referenced Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants