Skip to content

MNT: Add more defaults to the stubs#1728

Open
loicdiridollou wants to merge 1 commit intopandas-dev:mainfrom
loicdiridollou:ghxxx_defaults
Open

MNT: Add more defaults to the stubs#1728
loicdiridollou wants to merge 1 commit intopandas-dev:mainfrom
loicdiridollou:ghxxx_defaults

Conversation

@loicdiridollou
Copy link
Copy Markdown
Member

@loicdiridollou loicdiridollou commented Apr 17, 2026

  • 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 used AI to develop this pull request, I prompted it to follow AGENTS.md.

About 500 instances of ellipsis removed and replaced with the proper default value so help with IDE hovering.
It remains around 1900 instances of ellipsis, we won't be able to clean them all since some use lib.no_default but we should be able to do some good progress there.

cls,
value: str | float | Timedelta | Tick | timedelta | np.timedelta64 = ...,
unit: TimeDeltaUnitChoices = ...,
unit: TimeDeltaUnitChoices = "ns",
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.

In Timedelta.__new__, the unit parameter actually defaults to None at runtime, although the docstring mentions "ns". Using None allows the constructor to handle input resolution correctly.

Ground Truth: timedeltas.pyx#L2147

Gemini 3 created, I verified

Comment thread pandas-stubs/io/sql.pyi
columns: list[str] | None = None,
*,
chunksize: int,
dtype_backend: DtypeBackend | NoDefault = ...,
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.

The read_sql_table function does not enforce keyword-only arguments for chunksize in the pandas 3.0 source. The * should be removed to maintain positional compatibility.

Ground Truth: io/sql.py#L257

Gemini 3 created, I verified

sharey: bool = ...,
layout: tuple[int, int] = ...,
figsize: tuple[float, float] = ...,
sharex: bool = False,
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.

For sharex, sharey, and legend, the runtime often uses None as a default to trigger context-aware logic (e.g., sharex depends on whether an ax is passed). Setting these to False in the stubs might be misleading. I suggest using None where the runtime signature does.

Ground Truth: plotting/_core.py#L1112

Signed, Gemini 3

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.

Edit: maybe github.com/pandas-dev/pandas/blob/main/pandas/plotting/_core.py#L1050, where it says None for sharex, but False for sharey. This is confusing.

self,
*,
axis: AxisInt | None = None,
dtype: DtypeArg | None = None,
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.

These reduction methods (sum, std, etc.) can return NaT (represented as NaTType) when skipna=False or on empty inputs. The return type should be expanded to Timedelta | NaTType.

Ground Truth: core/arrays/timedeltas.py#L367 (via _box_func)

Gemini 3 created, I verified

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think we should return Timedelta | NaTType in this case because it will force users to do a cast when they know the result is valid. I'd be OK with an overload with skipna=False that returned Timedelta | NaTType

storage_options: StorageOptions = None,
dtype_backend: DtypeBackend | NoDefault = ...,
engine: Literal["ujson"] = ...,
engine: Literal["ujson"] = "ujson",
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.

The engine parameter supports more than just "ujson". It should use the JSONEngine type alias to include "pyarrow".

Ground Truth: io/json/_json.py#L535

Gemini 3 created, I verified

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