Skip to content

DOC: Add Examples section to append_fields in numpy.lib.recfunctions#31544

Open
lakshit2234 wants to merge 2 commits into
numpy:mainfrom
lakshit2234:doc/add-examples-append-fields
Open

DOC: Add Examples section to append_fields in numpy.lib.recfunctions#31544
lakshit2234 wants to merge 2 commits into
numpy:mainfrom
lakshit2234:doc/add-examples-append-fields

Conversation

@lakshit2234
Copy link
Copy Markdown

What this PR does

Added an Examples section to the append_fields function in
numpy/lib/recfunctions.py, which was missing documentation examples.

The examples demonstrate:

  • Appending a single field to an existing structured array
  • Appending multiple fields at once

AI Disclosure

  • Tool used: Claude (Anthropic)
  • How it was used: Claude assisted in identifying the missing
    Examples section and suggesting the structure of the docstring example.
  • What is AI generated: The initial draft of the Examples section
    was AI-assisted.
  • Human verification: All example outputs were manually verified
    by running the code locally. I understand the code fully and take
    complete responsibility for this contribution.

Copilot AI review requested due to automatic review settings May 31, 2026 14:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds illustrative usage examples to the append_fields docstring to clarify how to append one or multiple fields to a structured array.

Changes:

  • Added a basic example appending a single field to a structured array.
  • Added an example demonstrating appending multiple fields in one call.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread numpy/lib/recfunctions.py
Comment on lines +684 to +701
Examples
--------
>>> import numpy as np
>>> from numpy.lib.recfunctions import append_fields
>>> base = np.array([(1, 2.0), (3, 4.0)], dtype=[('x', int), ('y', float)])
>>> new_field = np.array([10, 20])
>>> append_fields(base, 'z', new_field, usemask=False)
array([(1, 2., 10), (3, 4., 20)],
dtype=[('x', '<i4'), ('y', '<f8'), ('z', '<i4')])

Append multiple fields at once:

>>> a = np.array([1, 2, 3])
>>> b = np.array([4.0, 5.0, 6.0])
>>> base = np.array([(1,), (2,), (3,)], dtype=[('x', int)])
>>> append_fields(base, ['a', 'b'], [a, b], usemask=False)
array([(1, 1, 4.), (2, 2, 5.), (3, 3, 6.)],
dtype=[('x', '<i4'), ('a', '<i4'), ('b', '<f8')])
@jorenham
Copy link
Copy Markdown
Member

We don't allow copilot reviews.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants