Repository: pandas-dev/pandas
Pull request #60271 (2024-11-09 17:51:38)

ENH: set __module__ on isna and notna
- [ ] Part of #55178 (Replace xxxx with the GitHub issue number)
- [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions.
- [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.


chanshing: `pd.notna` is top-level too and is defined in missing.py, so maybe could be included in this PR
https://github.com/pandas-dev/pandas/blob/217a0ed7f1e04dd675d0887ead001cbf2e91d880/pandas/core/dtypes/missing.py#L316
SiemBerhane: > Thanks @SiemBerhane

Glad it finally works. Thanks for your help!
simonjayhawkins: @jorisvandenbossche 

`isnull` and `notnull` are aliases to `isna` and `notna` respectively that are also defined in `pandas/core/dtypes/missing.py`

now the documentation for isnull is the same as isna (because it's just an alias to isna).

should the docs additionally mention that is an alias? are `isnull` and `notnull` recommended uses?

in IPython the repr now for pd.isnull is `<function pandas.isna(obj: 'object') -> 'bool | npt.NDArray[np.bool_] | NDFrame'>`. While we're improving the output formatting is there any value in making this show `<function pandas.isnull....` instead?

would we also want an assert in the tests for pd.isnull and pd.notnull too?




Patch:
diff --git a/pandas/core/dtypes/missing.py b/pandas/core/dtypes/missing.py
index b9cd6ae2f1..f20ca44728 100644
--- a/pandas/core/dtypes/missing.py
+++ b/pandas/core/dtypes/missing.py
@@ -19,6 +19,7 @@ from pandas._libs.tslibs import (
     NaT,
     iNaT,
 )
+from pandas.util._decorators import set_module
 
 from pandas.core.dtypes.common import (
     DT64NS_DTYPE,
@@ -93,6 +94,7 @@ def isna(
 def isna(obj: object) -> bool | npt.NDArray[np.bool_] | NDFrame: ...
 
 
+@set_module("pandas")
 def isna(obj: object) -> bool | npt.NDArray[np.bool_] | NDFrame:
     """
     Detect missing values for an array-like object.
@@ -307,6 +309,7 @@ def notna(
 def notna(obj: object) -> bool | npt.NDArray[np.bool_] | NDFrame: ...
 
 
+@set_module("pandas")
 def notna(obj: object) -> bool | npt.NDArray[np.bool_] | NDFrame:
     """
     Detect non-missing values for an array-like object.


Test patch:
diff --git a/pandas/tests/api/test_api.py b/pandas/tests/api/test_api.py
index 8209ff86c6..75f9958b16 100644
--- a/pandas/tests/api/test_api.py
+++ b/pandas/tests/api/test_api.py
@@ -417,6 +417,8 @@ def test_set_module():
     assert pd.Period.__module__ == "pandas"
     assert pd.Timestamp.__module__ == "pandas"
     assert pd.Timedelta.__module__ == "pandas"
+    assert pd.isna.__module__ == "pandas"
+    assert pd.notna.__module__ == "pandas"
     assert pd.merge.__module__ == "pandas"
     assert pd.merge_ordered.__module__ == "pandas"
     assert pd.merge_asof.__module__ == "pandas"