SciSharp / SciSharp/NumSharp

[NEP32 NEP34] API Cleanup and Behavioral Changes

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

@Nucs is already working on this.

Since Feb 18, 2026.

api documentation-needed enhancement NumPy 2.x Compliance
Dominant language
C#
Stars
1.5k
Forks
205
Avg merge
7d 7h
Merged PRs (30d)
2

Description

Overview

NumPy's removal of financial functions and changes to dtype inference behavior.


NEP 32: Remove Financial Functions

Status: Final | Full Text

Removed Functions
Function Description
fv Future value
pv Present value
npv Net present value
irr Internal rate of return
mirr Modified internal rate of return
nper Number of periods
pmt Payment
ppmt Principal payment
ipmt Interest payment
rate Rate of return
Rationale
  • Too specialized for NumPy's core mission
  • Cannot handle actual dates/calendars
  • Low usage (only 8 GitHub repos found)
  • Little maintainer interest
Timeline
  • NumPy 1.18: Deprecated with warnings
  • NumPy 1.20: Removed
Replacement

numpy-financial package on PyPI.


NEP 34: Disallow Inferring dtype=object

Status: Final | Full Text

Behavior Change
Before (NumPy 1.x)
# Silent object dtype for ragged sequences
np.array([[1, 2], [1]])
# array([[1, 2], [1]], dtype=object)
After (NumPy 2.x)
# Raises ValueError
np.array([[1, 2], [1]])
# ValueError: cannot guess the desired dtype
Cases That Raise
# Ragged sequences
np.array([[1, 2], [1]])

# Mixed sequences and non-sequences
np.array([np.arange(10), [10]])

# Mixed types within sequences
np.array([[range(3), range(3)], [range(3), 0]])
Explicit dtype=object
# Still works when explicit
np.array([[1, 2], [1]], dtype=object)

Suggested Implementation for NumSharp

Financial Functions

DO NOT IMPLEMENT. These are outside NumSharp's scope. Users needing financial calculations should use dedicated C# libraries.

dtype=object Inference
Ragged Sequence Detection
public static NDArray array(object input, NPTypeCode? dtype = null) {
    if (IsRaggedSequence(input)) {
        if (dtype == NPTypeCode.Object) {
            // Explicit request - allow
            return CreateObjectArray(input);
        }
        throw new ValueError(
            "Cannot guess dtype from ragged sequence. " +
            "Use dtype=object explicitly.");
    }
    // Normal array creation
}

private static bool IsRaggedSequence(object input) {
    // Check if nested sequences have mismatched lengths
    if (input is IEnumerable outer) {
        int? expectedLength = null;
        foreach (var item in outer) {
            if (item is IEnumerable inner) {
                int len = inner.Cast<object>().Count();
                if (expectedLength == null) {
                    expectedLength = len;
                } else if (len != expectedLength) {
                    return true;  // Ragged
                }
            }
        }
    }
    return false;
}
Dead Code Audit

Per CLAUDE.md, these functions need attention:

Function Current State Action
np.linalg.norm private static Make public or remove
nd.inv() returns null Throw NotImplementedException
nd.qr() returns default Throw NotImplementedException
nd.svd() returns default Throw NotImplementedException
nd.lstsq() returns null Throw NotImplementedException
np.isnan returns null Implement or throw
np.isfinite returns null Implement or throw
np.isclose returns null Implement or throw
operator & returns null Implement or throw
operator | returns null Implement or throw
Buggy Functions
Function Issue Fix
np.any with axis Always throws Fix implementation
nd.roll() Limited types Extend to all types
Boolean mask setter NotImplementedException Implement

Documentation

See docs/neps/NEP32.md, docs/neps/NEP34.md

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.