Skip to content

Create category.pyi #30093

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
Open

Create category.pyi #30093

wants to merge 1 commit into from

Conversation

Santt997
Copy link

@Santt997 Santt997 commented May 22, 2025

PR summary

PR checklist

@story645
Copy link
Member

Hi @Santt997, I suggest you install and run the precommit hooks to help fix the linting errors https://matplotlib.org/devdocs/devel/development_setup.html#install-pre-commit-hooks

Comment on lines +1 to +11
"""
Plotting of string "category" data: ``plot(['d', 'f', 'a'], [1, 2, 3])`` will
plot three points with x-axis values of 'd', 'f', 'a'.

See :doc:`/gallery/lines_bars_and_markers/categorical_variables` for an
example.

The module uses Matplotlib's `matplotlib.units` mechanism to convert from
strings to integers and provides a tick locator, a tick formatter, and the
`.UnitData` class that creates and stores the string-to-integer mapping.
"""
Copy link
Member

Choose a reason for hiding this comment

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

The .pyi files don't typically have doc strings

class StrCategoryConverter(ConversionInterface):
@staticmethod
def convert(
value: Union[str, Iterable[str]],
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
value: Union[str, Iterable[str]],
value: str | Iterable[str],

The .pyi files typically use the union operator rather than explicit union, please make this change to all the unions in this file
https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html


class StrCategoryFormatter(ticker.Formatter):
def __init__(self, units_mapping: Dict[str, int]) -> None: ...
def __call__(self, x: float, pos: Optional[int] = None) -> str: ...
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def __call__(self, x: float, pos: Optional[int] = None) -> str: ...
def __call__(self, x: float, pos: int | None) -> str: ...

also use the | convetion for optional, see https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html


class UnitData:
_mapping: OrderedDict[Union[str, bytes], int]
def __init__(
Copy link
Member

Choose a reason for hiding this comment

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

I think ._counter also needs to be documented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs review
Development

Successfully merging this pull request may close these issues.

2 participants