Skip to content

Conversation

cjdoris
Copy link
Collaborator

@cjdoris cjdoris commented Sep 13, 2025

  • Adds a public NumpyDates submodule with types:
    • AbstractDateTime64, DateTime64, InlineDateTime64
    • AbstractTimeDelta64, TimeDelta64, InlineTimeDelta64
  • Adds conversions from numpy.datetime64 and numpy.timedelta64 to these types.
  • Adds conversions from arrays of these to PyArray.
  • Tests for all of the above.

Todo:

  • Tests for NumpyDates.
  • Tests for conversion of numpy scalars to these types.
  • Tests for conversion of numpy arrays to these types.
  • Update changelog.
  • Update docs.

Christopher Doris added 23 commits September 7, 2025 10:52
Implement constructors, accessors, and display for TimeDelta64 and
InlineTimeDelta64. Add conversions from Dates.Period and NaT strings.
Unify NaT handling via NAT sentinel. Replace unit access with
unitpair and store units as (Unit, Cint). Provide defaultunit and a
showvalue helper; update isnan to use NAT. Changing units between
instances is not yet implemented (except for NaT).

BREAKING CHANGE: TimeDelta64 fields changed from unit_base/unit_scale
to unit::Tuple{Unit,Cint}. The unit(...) accessor is removed; use
unitpair(d) instead. The generic Dates.value(::AbstractTimeDelta64)
method was removed; use Dates.value on concrete types.
Use Dates.year(d) and Dates.month(d) in the Date-based constructor
instead of value(Dates.Year(d)) and value(Dates.Month(d)). The
previous approach could error or yield wrong values when computing
YEAR/MONTH offsets relative to 1970, affecting YEARS and MONTHS units.

Also includes minor whitespace cleanup.
Add NumpyDates tests verifying Date conversions to DateTime64 and
InlineDateTime64 across units Y, M, D, h, m, s, ms, us, ns, comparing
against expected int values.

Covers:
- DateTime64(Date, Symbol)
- InlineDateTime64{U}(Date)
- InlineDateTime64(Date, Symbol)
and checks Dates.value and unitpair correctness.

Add test/scripts/np_dates.py to generate NumPy-based ground-truth
int64 values for selected dates.
- Replace ÷ with fld in conversions to apply floor semantics for
  negative values, matching NumPy datetime64 behavior
- Correct ATTOSECONDS multiplier to 1e15
- Add comprehensive DateTime -> DateTime64/InlineDateTime64 tests,
  including pre-epoch cases, and refine existing Date tests
- Add script to generate NumPy reference values for tests
Add module docstring and detailed docs for Unit enum and datetime/
timedelta types (DateTime64, InlineDateTime64, TimeDelta64,
InlineTimeDelta64), including accepted constructor inputs and unit
references. Document supertypes AbstractDateTime64 and
AbstractTimeDelta64. No functional changes.
- Add NumpyDates section to pythoncall-reference with API docs
- Update release notes with NumpyDates overview
- Clarify docstrings: runtime vs inline units and memory layout
Add mapping entries for numpy.datetime64 and numpy.timedelta64 in
conversion-to-julia.md. Document conversion to NumpyDates types and
inline/Dates fallbacks to clarify behavior when passing numpy date/time
objects from Python.
…escale function

- Add pyconvert rules for InlineDateTime64 and InlineTimeDelta64 types
- Refactor DateTime64 and TimeDelta64 constructors to use rescale for unit conversions
- Introduce unitscale and rescale functions in Unit.jl for efficient scaling between units
- Add convert methods for DatesInstant and DatesPeriod types
- Update common.jl with new type aliases and helper functions
- Enhance tests for new conversion capabilities and error handling

These changes streamline the conversion logic, reduce code duplication, and improve performance by centralizing unit scaling operations. No breaking changes to public APIs.
…for datetime64 and timedelta64

- Implement rescale function to handle unit changes in DateTime64 and TimeDelta64 instead of throwing errors
- Expand Base.convert methods for InlineDateTime64 and InlineTimeDelta64 to support more types
- Add new pyconvert rules for NumpyDates.DatesInstant and NumpyDates.DatesPeriod in numpy.jl

This enhances type conversions and removes previous limitations on unit scaling.
…delta support

- Simplified accessor functions in DateTime64, InlineDateTime64, InlineTimeDelta64, and TimeDelta64 by removing unnecessary function wrappers
- Added support for NumpyDates.InlineDateTime64 and InlineTimeDelta64 in pyjlarray_isarrayabletype and pytypestrdescr
- Refactored pytypestrdescr to use if-elseif structure for better readability
- Updated PyArray.jl to handle unbound units in type conversion

This enhances numpy date type integration while cleaning up code structure.
…edelta types

Ensure that type T is concrete before checking if it subtypes the union of InlineDateTime64 and InlineTimeDelta64, preventing potential issues with abstract types in pytypestrdescr function.
@cjdoris cjdoris merged commit 3633da0 into main Sep 17, 2025
15 checks passed
@cjdoris cjdoris deleted the numpy-dates branch September 17, 2025 14:51
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.

1 participant