Skip to content

TYP: Shape-typing in PlotAccessor - #2071

Open
jorenham wants to merge 1 commit into
pandas-dev:mainfrom
jorenham:PlotAccessor/shape-typing
Open

jorenham wants to merge 1 commit into
pandas-dev:mainfrom
jorenham:PlotAccessor/shape-typing

Conversation

@jorenham

@jorenham jorenham commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

The PlotAccessor method overloads returning object_ numpy arrays now return a 1d array when layout=None (default) and 2d array when layout: tuple[int, int].

For consistency with np_1darray_object, I introduced a new _typing alias for the 2d case; hope that's ok.

  • Closes #xxxx (Replace xxxx with the Github issue number)
  • Tests added (Please use assert_type() to assert the type of any return value)
  • If I add a new API, it is already listed as public in the pandas API reference.
  • If I used AI to develop this pull request, I prompted it to follow AGENTS.md.

Comment thread tests/test_plotting.py Outdated
check(assert_type(IRIS_DF.plot.line(), Axes), Axes)
check(assert_type(IRIS_DF.plot(kind="line"), Axes), Axes)
check(assert_type(IRIS_DF.plot.line(subplots=True), np_ndarray_object), np.ndarray)
check(assert_type(IRIS_DF.plot.line(subplots=True), np_1darray_object), np.ndarray)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
check(assert_type(IRIS_DF.plot.line(subplots=True), np_1darray_object), np.ndarray)
check(assert_type(IRIS_DF.plot.line(subplots=True), np_1darray_object), np_1darray_object)

basically we try to avoid using np.ndarray and use np_1darray, np_2darray, np_ndarray or their variations, like #1588. Please also propagate the idea to other places and other PRs that you own.

@jorenham
jorenham force-pushed the PlotAccessor/shape-typing branch from a26bbc3 to 0b38daf Compare November 5, 2026 14:51
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.

2 participants