-
Notifications
You must be signed in to change notification settings - Fork 204
Open
Labels
NumPy 2.x ComplianceAligns behavior with NumPy 2.x (NEPs, breaking changes)Aligns behavior with NumPy 2.x (NEPs, breaking changes)apiPublic API surface (np.*, NDArray methods, operators)Public API surface (np.*, NDArray methods, operators)documentation-neededFeature requires documentation after implementation or depiction of lack of documentationFeature requires documentation after implementation or depiction of lack of documentationenhancementNew feature or requestNew feature or request
Milestone
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 dtypeCases 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
NumPy 2.x ComplianceAligns behavior with NumPy 2.x (NEPs, breaking changes)Aligns behavior with NumPy 2.x (NEPs, breaking changes)apiPublic API surface (np.*, NDArray methods, operators)Public API surface (np.*, NDArray methods, operators)documentation-neededFeature requires documentation after implementation or depiction of lack of documentationFeature requires documentation after implementation or depiction of lack of documentationenhancementNew feature or requestNew feature or request