SciSharp / SciSharp/NumSharp

[Types] Add datetime64 support

Open
#570 0 comments 0 reactions 1 assignee View on GitHub

@Nucs is already working on this.

Since Feb 18, 2026.

core documentation-needed enhancement missing feature/s
Dominant language
C#
Stars
1.5k
Forks
205
Avg merge
7d 7h
Merged PRs (30d)
2

Description

Overview

Add support for datetime64 type to NumSharp for time series and data science workloads.

Problem

NumSharp lacks datetime support, which is essential for:

>>> import numpy as np
>>> np.array(['2024-01-15', '2024-06-30'], dtype='datetime64[D]')
array(['2024-01-15', '2024-06-30'], dtype='datetime64[D]')

>>> np.datetime64('2024-01-15') + np.timedelta64(30, 'D')
numpy.datetime64('2024-02-14')

>>> np.arange('2024-01', '2024-06', dtype='datetime64[M]')
array(['2024-01', '2024-02', '2024-03', '2024-04', '2024-05'], dtype='datetime64[M]')

Use cases:

  • Time series analysis — Financial data, sensor data, logs
  • Pandas interop — Pandas uses NumPy datetime64 internally
  • Data science — Date ranges, filtering, aggregation
  • File I/O — Many datasets have datetime columns

Proposal

Task List
  • Design datetime64 representation (epoch + unit)
  • Create DateTime64 struct with unit awareness:
    public readonly struct DateTime64
    {
        public readonly long Value;  // Ticks from epoch
        public readonly DateTimeUnit Unit;  // ns, us, ms, s, m, h, D, W, M, Y
    }
    
  • Add NPTypeCode.DateTime64 to NPTypeCode.cs
  • Implement unit conversion logic
  • Implement parsing from strings ("2024-01-15", "2024-01-15T12:30:00")
  • Implement arithmetic (datetime + timedelta)
  • Implement comparison operators
  • Add np.datetime64() constructor
  • Update type promotion tables
  • Add tests with NumPy verification
Units (matching NumPy)
Unit Code Description
Y Year
M Month
W Week
D Day
h Hour
m Minute
s Second
ms Millisecond
us Microsecond
ns Nanosecond Default
C# Type Mapping Options
NumPy C# Option Notes
datetime64 DateTime64 struct Custom, epoch-based with unit
datetime64 DateTime Limited to 100ns precision
datetime64 DateTimeOffset Has timezone, may be overkill

Implementation Effort

MEDIUM — Requires unit handling, parsing, arithmetic with timedelta64.

Estimated: ~500 lines for struct, parsing, and operations.

Related

  • Part of NumPy 2.x alignment: #529
  • Will benefit from DynamicMethod IL emission: #544
  • Depends on: timedelta64 support for full arithmetic

References

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.