Skip to content

DOC: Clarify float-to-int truncation behavior in numpy.array_split documentation #29511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JRedrupp
Copy link

@JRedrupp JRedrupp commented Aug 5, 2025

Summary

Fixes #29494 by clarifying how numpy.array_split handles floating-point inputs.

Changes

  • Added comprehensive Parameters section: Documents that floating-point indices_or_sections values are truncated towards zero using int() before splitting
  • Added practical example: Shows np.array_split(x, 3.9) being treated as np.array_split(x, 3)
  • Added Returns section: For documentation completeness
  • Fixed doctest formatting: Corrected spacing in existing array output examples for consistency

Example of the clarified behavior

import numpy as np
x = np.arange(10)

# These are equivalent:
np.array_split(x, 3.9)  # Treated as 3
np.array_split(x, 3)
# Both return: [array([0, 1, 2, 3]), array([4, 5, 6]), array([7, 8, 9])]

Add comprehensive documentation explaining that floating-point
indices_or_sections values are truncated towards zero using int()
before splitting. This addresses user confusion about unexpected
behavior when passing float values like 3.9 to array_split.

Changes:
- Add Parameters section documenting float truncation behavior
- Add example showing np.array_split(x, 3.9) treated as 3 sections
- Add Returns section for completeness
- Fix existing doctest formatting for consistency

Closes numpygh-29494

If `indices_or_sections` is a floating-point number, it will be
truncated towards zero (equivalent to ``int()``) before splitting.
For example, ``3.9`` is treated as ``3``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care if this is true, but let's not document the float input. If anything, that should be deprecated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: Clarify float-to-int truncation behavior in numpy.array_split documentation
2 participants