Skip to content

Conversation

meet-vasita
Copy link
Contributor

Set __module__ = "pandas" on NaTType and NAType to fix incorrect autodoc "alias of" messages.
Closes #62185.

meet-vasita and others added 3 commits September 11, 2025 01:06
…s message

Set __module__ = 'pandas' on NaTType and NAType to fix incorrect autodoc 'alias of' messages.
Closes pandas-dev#62185.
Fixes Sphinx autodoc showing circular 'alias of' references
for pandas.NA and pandas.NaT by explicitly setting their
__module__ attribute to 'pandas'.

Closes pandas-dev#62185
@meet-vasita
Copy link
Contributor Author

meet-vasita commented Sep 10, 2025

Hi @rhshadrach, I've implemented your suggested fix by adding __module__ = "pandas" to both NAType and NaTType classes.

Would you be able to review this PR when you have a chance? Thanks for identifying the root cause and providing the solution direction.

@simonjayhawkins
Copy link
Member

/docbuild

@simonjayhawkins
Copy link
Member

/preview

Copy link
Contributor

Website preview of this PR available at: https://pandas.pydata.org/preview/pandas-dev/pandas/62313/

@simonjayhawkins
Copy link
Member

@rhshadrach
Copy link
Member

rhshadrach commented Sep 15, 2025

Thanks @meet-vasita and @simonjayhawkins - I think the remaining issue is that NA and NaT are not classes, they are instances of classes. I don't believe instances play well with autodoc. I get the "desired" output by changing https://github.com/pandas-dev/pandas/blob/main/doc/source/reference/missing_value.rst to use

api.typing.NAType

and

api.typing.NaTType

But there is the less-than desired effect of having the class show up in the API page. Open to thoughts here.

@wjandrea
Copy link
Contributor

wjandrea commented Sep 19, 2025

@rhshadrach I'm out of my depth on Sphinx, but the SO page you linked had these comments - do they help?

  • "If you do this then you break inspect.getsource(Foo)" — Eric
  • "Do this in the setup function in conf.py and then you won't mess with anything in the original source code. For example: github.com/slundberg/shap/blob/…" — slund

@rhshadrach
Copy link
Member

@wjandrea - no, we'd still face the issue I identified in my previous comment.

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Sep 22, 2025

Since this worked fine in the past, this might be caused by c8e7a98, which while deduplicating the entry also added a :template: autosummary/class_without_autosummary.rst (originally, the first occurence did not have that).

Testing it out locally, removing that line from doc/source/reference/missing_value.rst seems to fix it

@jorisvandenbossche
Copy link
Member

(and we can keep the __module__ changes, I think, since they are useful anyway regardless of the doc issue)

@jorisvandenbossche jorisvandenbossche added this to the 2.3.3 milestone Sep 22, 2025
@rhshadrach rhshadrach modified the milestones: 2.3.3, 2.3.4 Sep 30, 2025
Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

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

lgtm

@rhshadrach rhshadrach changed the title Fix NaT and NA docs: Set __module__ to "pandas" to prevent wrong alias message DOC: Fix NaT and NA API docs Sep 30, 2025
@rhshadrach rhshadrach added the Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate label Sep 30, 2025
@rhshadrach rhshadrach merged commit 5cc3240 into pandas-dev:main Sep 30, 2025
47 of 49 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Sep 30, 2025
@rhshadrach
Copy link
Member

Thanks @meet-vasita!

@meet-vasita
Copy link
Contributor Author

You’re welcome @rhshadrach, I’m glad it was helpful.

jzwick pushed a commit to jzwick/pandas that referenced this pull request Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docs Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOC: NaT - "alias of NaT"; NA - "alias of <NA>"

5 participants