GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add type hints for matplotlib.dates module by bandpooja · Pull Request #30126 · matplotlib/matplotlib

Conversation

@bandpooja

@bandpooja bandpooja commented Jun 1, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

PR Summary

This pull request introduces comprehensive type hint stubs (.pyi files) for the matplotlib.dates module.

Why this change is necessary:
By providing explicit type information, this enhancement significantly improves static type checking capabilities for matplotlib.dates. Developers using tools like MyPy, Pyright, or Ruff can now catch potential type-related errors earlier in the development cycle, leading to more robust and maintainable code.

Problem solved:
This PR addresses the current lack of precise type information for matplotlib.dates classes and functions during static analysis. It makes the module's API more explicit and easier for automated type-checking tools to understand and validate.

Implementation reasoning:
The implementation involves adding .pyi files that define the types for the core classes and functions within matplotlib.dates.py. This change directly contributes to Matplotlib's ongoing initiative to expand and improve type hinting coverage across its codebase, fostering better developer experience and code quality.

Closes #29994

PR Checklist

  • "closes Missing type hints for matplotlib.dates.DateFormatter #29994" is in the body of the PR description to link the related issue
  • new and changed code is tested
    • Note: For type stub additions, "tested" typically means running mypy or similar type checkers to ensure no errors are introduced.

Test Result

mypy, ruff and Pyright with the new dates.pyi
Screenshot 2025-06-01 at 4 22 20 AM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

johnthagen and Anshul22Verma reacted with heart emoji
All reactions
  • ❤️ 2 reactions
bandpooja added 2 commits June 1, 2025 02:53
@bandpooja
adding stub-file for dates module
b5c7c2b
@bandpooja
import and type hint corrections
3a7ac41
@github-actions github-actions Bot added the topic: date handling label Jun 1, 2025
@bandpooja
bandpooja marked this pull request as draft June 1, 2025 07:41
@bandpooja
bandpooja marked this pull request as ready for review June 1, 2025 07:42
github-actions[bot]
github-actions Bot reviewed Jun 1, 2025
View reviewed changes

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
bandpooja added 3 commits June 1, 2025 03:46
@bandpooja
adding a ruff test pass as well
e485a7d
@bandpooja
passing the pyright test
aee2931
@bandpooja
passing all the tests
e75fe2b
@bandpooja bandpooja mentioned this pull request Jun 1, 2025
Missing type hints for matplotlib.dates.DateFormatter #29994
Closed
timhoffm
timhoffm reviewed Jun 2, 2025
View reviewed changes
Comment thread lib/matplotlib/dates.pyi Resolved

Uh oh!

There was an error while loading. Please reload this page.

@tacaswell tacaswell added this to the v3.11.0 milestone Jun 2, 2025
@bandpooja
removing Optional and Union to remain consistent with other pyi files
8a0f20f
QuLogic
QuLogic reviewed Jun 3, 2025
View reviewed changes

@QuLogic QuLogic left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I've only done up to the formatters; please correct the default values in the rest.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/matplotlib/dates.pyi Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/matplotlib/dates.pyi Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/matplotlib/dates.pyi Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/matplotlib/dates.pyi Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/matplotlib/dates.pyi Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/matplotlib/dates.pyi Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/matplotlib/dates.pyi Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/matplotlib/dates.pyi Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/matplotlib/dates.pyi Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/matplotlib/dates.pyi Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bandpooja
correcting overload for datestr2num
dde90a5
@bandpooja

bandpooja commented Jun 10, 2025

Copy link
Copy Markdown
Author

Thanks for the review @QuLogic.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic

QuLogic commented Jun 10, 2025

Copy link
Copy Markdown
Member

I've only done up to the formatters; please correct the default values in the rest.

Please handle the rest of these.

bandpooja reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bandpooja
correcting all the default values
8f448fe
@bandpooja

bandpooja commented Jun 10, 2025

Copy link
Copy Markdown
Author

Done thanks again !!
Learning to write .pyi files. 😅

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bandpooja
ruffdog newline at the end of file
64270ee
@melissawm melissawm added this to First Time Contributors Jun 19, 2025
@melissawm melissawm moved this to Needs review in First Time Contributors Jun 19, 2025
QuLogic
QuLogic reviewed Jun 20, 2025
View reviewed changes
Comment thread lib/matplotlib/dates.pyi
fmt: str

def __init__(self, fmt: str, tz: str | datetime.tzinfo | None = ..., *, usetex: bool | None = ...) -> None: ...
def __call__(self, x: float, pos: int | None = ...) -> str: ...

@QuLogic QuLogic Jun 20, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This inherits from Formatter, so can be dropped.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/matplotlib/dates.pyi
zero_formats: Sequence[str] | None = ...,
show_offset: bool = ...,
*, usetex: bool | None = ...) -> None: ...
def __call__(self, x: float, pos: int | None = ...) -> str: ...

@QuLogic QuLogic Jun 20, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ditto.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/matplotlib/dates.pyi
defaultfmt: str = ...,
*, usetex: bool | None = ...) -> None: ...
def _set_locator(self, locator: Locator) -> None: ...
def __call__(self, x: float, pos: int | None = ...) -> str: ...

@QuLogic QuLogic Jun 20, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ditto.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/matplotlib/dates.pyi
show_offset: bool = ...,
*, usetex: bool | None = ...) -> None: ...
def __call__(self, x: float, pos: int | None = ...) -> str: ...
def format_ticks(self, values: Sequence[float]) -> list[str]: ...

@QuLogic QuLogic Jun 20, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Also inherited.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/matplotlib/dates.pyi
def __call__(self, x: float, pos: int | None = ...) -> str: ...
def format_ticks(self, values: Sequence[float]) -> list[str]: ...
def get_offset(self) -> str: ...
def format_data_short(self, value: float) -> str: ...

@QuLogic QuLogic Jun 20, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Also inherited.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/matplotlib/dates.pyi
Comment on lines +184 to +185
@staticmethod
def axisinfo(unit: datetime.tzinfo | None, axis: Axis) -> None: ...

@QuLogic QuLogic Jun 20, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This isn't a static method, and doesn't return None.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/matplotlib/dates.pyi
@staticmethod
def axisinfo(unit: datetime.tzinfo | None, axis: Axis) -> None: ...
@staticmethod
def convert(obj: datetime.datetime | datetime.date | float | np.datetime64 | Sequence[datetime.datetime | datetime.date | float | np.datetime64],

@QuLogic QuLogic Jun 20, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

obj is named value in the source. Also where did float and datetime.date input come from? This goes through date2num which takes datetime.datetime | np.datetime64.

And probably this should be overloaded like date2num.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/matplotlib/dates.pyi
Comment on lines +198 to +199
@staticmethod
def axisinfo(unit: datetime.tzinfo | None, axis: Axis) -> None: ...

@QuLogic QuLogic Jun 20, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Same as above, isn't static and doesn't return None.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/matplotlib/dates.pyi

class _SwitchableDateConverter:
@staticmethod
def _get_converter() -> "ConciseDateConverter" | "DateConverter": ...

@QuLogic QuLogic Jun 20, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Note sure why these are quoted.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/matplotlib/dates.pyi
Comment on lines +205 to +212
@staticmethod
def axisinfo(unit: datetime.tzinfo | None, axis: Axis) -> AxisInfo: ...
@staticmethod
def default_units(x: datetime.datetime | datetime.date | float | np.ndarray | Sequence[datetime.datetime | datetime.date | float | np.datetime64],
axis: Axis) -> datetime.tzinfo | None: ...
@staticmethod
def convert(value: datetime.datetime | datetime.date | float | np.datetime64 | Sequence[datetime.datetime | datetime.date | float | np.datetime64],
unit: datetime.tzinfo | None, axis: Axis) -> float | np.ndarray: ...

@QuLogic QuLogic Jun 20, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

None of these are static.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@rcomer rcomer mentioned this pull request Aug 4, 2025
[Bug]: Missing typing for dates.py #26942
Open
@QuLogic QuLogic mentioned this pull request Aug 5, 2025
Add type stubs for functions in matplotlib.dates #30385
Merged
5 tasks
@dstansby

dstansby commented Aug 12, 2025

Copy link
Copy Markdown
Member

👋 @bandpooja I accidentally started work on this too at #30385 - are you still interested in finishing off this pull request? If you are, please let us know if you have any questions or can help at all. If not, it would be good to know and we can finish off the work you started :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tacaswell tacaswell modified the milestones: v3.11.0, future releases Apr 3, 2026
@tacaswell
tacaswell marked this pull request as draft April 3, 2026 20:05
@tacaswell

tacaswell commented Apr 3, 2026

Copy link
Copy Markdown
Member

I removed this from 3.11 and marked as draft because it has been quiet.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the status: needs rebase label Apr 3, 2026
@myzhang1029 myzhang1029 mentioned this pull request Jun 6, 2026
Add typing interface file and type hints for backends.backend_pdf #31854
Merged
1 of 5 tasks
@maaz7409 maaz7409 mentioned this pull request Oct 16, 2026
BLD: Install the type stub for backends.registry #32481
Merged
1 task done

This branch has not been deployed

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

Reviewers

@QuLogic QuLogic QuLogic left review comments
@timhoffm timhoffm timhoffm left review comments
@github-actions github-actions[bot] github-actions[bot] left review comments

At least 1 approving review is required to merge this pull request.

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

status: needs rebase topic: date handling

Projects

First Time Contributors
Status: Needs review

Milestone

future releases

Development

Successfully merging this pull request may close these issues.

Missing type hints for matplotlib.dates.DateFormatter

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@bandpooja @QuLogic @dstansby @tacaswell @timhoffm
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.