Skip to content

[ENH] Update chainladder.utils.sparse.floor(x) to return a copy of x #740

@genedan

Description

@genedan

Description

chainladder.utils.sparse.floor(x) mutates x, where x is a sparse COO array.

from chainladder.utils.sparse import (array, floor)

a = array([1.2, 2.7, -0.3])
floor(a)
a.todense()

results in:

array([ 1.,  2., -1.])

Is your feature request aligned with the scope of the package?

  • Yes, absolutely!
  • No, but it's still worth discussing.
  • N/A (this request is not a codebase enhancement).

Describe the solution you'd like, or your current workaround.

Since side effects are discouraged these days, and the analogous np.floor() returns a copy, I would recommend we also return a copy instead:

a = array([1.2, 2.7, -0.3])
floor(a)
a.todense()

Should result in:

array([1.2, 2.7, -0.3])

And to save back to a, we should do:

a = array([1.2, 2.7, -0.3])
a = floor(a)
a.todense()

resulting in:

array([ 1.,  2., -1.])

Do you have any additional supporting notes?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Effort > Brief 🐇Small tasks expected to take a few hours up to a couple of days.Impact > Minor 🔷Small, backward compatible change. Treat like a patch release (e.g., 0.5.8 → 0.5.9).Refactor 🔧Code level improvements that restructure existing logic without changing behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions