TYP overload fillna #40737
State: closed

- [x] closes #40737
- [x]  tests added / passed
- [x] Ensure all linting tests pass, see [here](https://pandas.pydata.org/pandas-docs/dev/development/contributing.html#code-standards) for how to run them

Labels:
name: Missing-data
description: np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
name: Typing
description: type annotations, mypy/pyright type checking

Comments:
@MarcoGorelli  Oh ok, I was under the impression that I needed an overload for each combination. I'll change it.
Nice! And great that this makes a couple of `cast`s redundant

Could include the output from running something like what was done in https://github.com/pandas-dev/pandas/pull/40860#issuecomment-817144849 ? I _think_ you might need to always include `=...` for default arguments which come _after_ `inplace` for it to work, but we'll see
Sure, I'll post it soon
@MarcoGorelli Yes, you were correct. `=...` was needed for it to work
Here are the inputs to and the outputs of mypy:
```
# DataFrame_t.py
import pandas as pd

inplace : bool

reveal_type(pd.DataFrame([1,2,3]).fillna(inplace=False))
reveal_type(pd.DataFrame([1,2,3]).fillna(value=0, inplace=False))
reveal_type(pd.DataFrame([1,2,3]).fillna(method='pad', inplace=False))
reveal_type(pd.DataFrame([1,2,3]).fillna(axis=0, inplace=False))
reveal_type(pd.DataFrame([1,2,3]).fillna(value=0, method='pad', inplace=False))
reveal_type(pd.DataFrame([1,2,3]).fillna(value=0, axis=0, inplace=False))
reveal_type(pd.DataFrame([1,2,3]).fillna(method='pad', axis=0, inplace=False))
reveal_type(pd.DataFrame([1,2,3]).fillna(value=0, method='pad', axis=0, inplace=False))

reveal_type(pd.DataFrame([1,2,3]).fillna(inplace=True))
reveal_type(pd.DataFrame([1,2,3]).fillna(value=0, inplace=True))
reveal_type(pd.DataFrame([1,2,3]).fillna(method='pad', inplace=True))
reveal_type(pd.DataFrame([1,2,3]).fillna(axis=0, inplace=True))
reveal_type(pd.DataFrame([1,2,3]).fillna(value=0, method='pad', inplace=True))
reveal_type(pd.DataFrame([1,2,3]).fillna(value=0, axis=0, inplace=True))
reveal_type(pd.DataFrame([1,2,3]).fillna(method='pad', axis=0, inplace=True))
reveal_type(pd.DataFrame([1,2,3]).fillna(value=0, method='pad', axis=0, inplace=True))

reveal_type(pd.DataFrame([1,2,3]).fillna(inplace=inplace))
reveal_type(pd.DataFrame([1,2,3]).fillna(value=0, inplace=inplace))
reveal_type(pd.DataFrame([1,2,3]).fillna(method='pad', inplace=inplace))
reveal_type(pd.DataFrame([1,2,3]).fillna(axis=0, inplace=inplace))
reveal_type(pd.DataFrame([1,2,3]).fillna(value=0, method='pad', inplace=inplace))
reveal_type(pd.DataFrame([1,2,3]).fillna(value=0, axis=0, inplace=inplace))
reveal_type(pd.DataFrame([1,2,3]).fillna(method='pad', axis=0, inplace=inplace))
reveal_type(pd.DataFrame([1,2,3]).fillna(value=0, method='pad', axis=0, inplace=inplace))
```
Output:
```
DataFrame_t.py:5: note: Revealed type is 'pandas.core.frame.DataFrame'
DataFrame_t.py:6: note: Revealed type is 'pandas.core.frame.DataFrame'
DataFrame_t.py:7: note: Revealed type is 'pandas.core.frame.DataFrame'
DataFrame_t.py:8: note: Revealed type is 'pandas.core.frame.DataFrame'
DataFrame_t.py:9: note: Revealed type is 'pandas.core.frame.DataFrame'
DataFrame_t.py:10: note: Revealed type is 'pandas.core.frame.DataFrame'
DataFrame_t.py:11: note: Revealed type is 'pandas.core.frame.DataFrame'
DataFrame_t.py:12: note: Revealed type is 'pandas.core.frame.DataFrame'
DataFrame_t.py:14: note: Revealed type is 'None'
DataFrame_t.py:15: note: Revealed type is 'None'
DataFrame_t.py:16: note: Revealed type is 'None'
DataFrame_t.py:17: note: Revealed type is 'None'
DataFrame_t.py:18: note: Revealed type is 'None'
DataFrame_t.py:19: note: Revealed type is 'None'
DataFrame_t.py:20: note: Revealed type is 'None'
DataFrame_t.py:21: note: Revealed type is 'None'
DataFrame_t.py:23: note: Revealed type is 'Union[pandas.core.frame.DataFrame, None]'
DataFrame_t.py:24: note: Revealed type is 'Union[pandas.core.frame.DataFrame, None]'
DataFrame_t.py:25: note: Revealed type is 'Union[pandas.core.frame.DataFrame, None]'
DataFrame_t.py:26: note: Revealed type is 'Union[pandas.core.frame.DataFrame, None]'
DataFrame_t.py:27: note: Revealed type is 'Union[pandas.core.frame.DataFrame, None]'
DataFrame_t.py:28: note: Revealed type is 'Union[pandas.core.frame.DataFrame, None]'
DataFrame_t.py:29: note: Revealed type is 'Union[pandas.core.frame.DataFrame, None]'
DataFrame_t.py:30: note: Revealed type is 'Union[pandas.core.frame.DataFrame, None]'
```
---
```
# Series_t.py
import pandas as pd

inplace : bool

reveal_type(pd.Series([1,2,3]).fillna(inplace=False))
reveal_type(pd.Series([1,2,3]).fillna(value=0, inplace=False))
reveal_type(pd.Series([1,2,3]).fillna(method='pad', inplace=False))
reveal_type(pd.Series([1,2,3]).fillna(axis=0, inplace=False))
reveal_type(pd.Series([1,2,3]).fillna(value=0, method='pad', inplace=False))
reveal_type(pd.Series([1,2,3]).fillna(value=0, axis=0, inplace=False))
reveal_type(pd.Series([1,2,3]).fillna(method='pad', axis=0, inplace=False))
reveal_type(pd.Series([1,2,3]).fillna(value=0, method='pad', axis=0, inplace=False))

reveal_type(pd.Series([1,2,3]).fillna(inplace=True))
reveal_type(pd.Series([1,2,3]).fillna(value=0, inplace=True))
reveal_type(pd.Series([1,2,3]).fillna(method='pad', inplace=True))
reveal_type(pd.Series([1,2,3]).fillna(axis=0, inplace=True))
reveal_type(pd.Series([1,2,3]).fillna(value=0, method='pad', inplace=True))
reveal_type(pd.Series([1,2,3]).fillna(value=0, axis=0, inplace=True))
reveal_type(pd.Series([1,2,3]).fillna(method='pad', axis=0, inplace=True))
reveal_type(pd.Series([1,2,3]).fillna(value=0, method='pad', axis=0, inplace=True))

reveal_type(pd.Series([1,2,3]).fillna(inplace=inplace))
reveal_type(pd.Series([1,2,3]).fillna(value=0, inplace=inplace))
reveal_type(pd.Series([1,2,3]).fillna(method='pad', inplace=inplace))
reveal_type(pd.Series([1,2,3]).fillna(axis=0, inplace=inplace))
reveal_type(pd.Series([1,2,3]).fillna(value=0, method='pad', inplace=inplace))
reveal_type(pd.Series([1,2,3]).fillna(value=0, axis=0, inplace=inplace))
reveal_type(pd.Series([1,2,3]).fillna(method='pad', axis=0, inplace=inplace))
reveal_type(pd.Series([1,2,3]).fillna(value=0, method='pad', axis=0, inplace=inplace))
```
Output:
```
Series_t.py:5: note: Revealed type is 'pandas.core.series.Series'
Series_t.py:6: note: Revealed type is 'pandas.core.series.Series'
Series_t.py:7: note: Revealed type is 'pandas.core.series.Series'
Series_t.py:8: note: Revealed type is 'pandas.core.series.Series'
Series_t.py:9: note: Revealed type is 'pandas.core.series.Series'
Series_t.py:10: note: Revealed type is 'pandas.core.series.Series'
Series_t.py:11: note: Revealed type is 'pandas.core.series.Series'
Series_t.py:12: note: Revealed type is 'pandas.core.series.Series'
Series_t.py:14: note: Revealed type is 'None'
Series_t.py:15: note: Revealed type is 'None'
Series_t.py:16: note: Revealed type is 'None'
Series_t.py:17: note: Revealed type is 'None'
Series_t.py:18: note: Revealed type is 'None'
Series_t.py:19: note: Revealed type is 'None'
Series_t.py:20: note: Revealed type is 'None'
Series_t.py:21: note: Revealed type is 'None'
Series_t.py:23: note: Revealed type is 'Union[pandas.core.series.Series, None]'
Series_t.py:24: note: Revealed type is 'Union[pandas.core.series.Series, None]'
Series_t.py:25: note: Revealed type is 'Union[pandas.core.series.Series, None]'
Series_t.py:26: note: Revealed type is 'Union[pandas.core.series.Series, None]'
Series_t.py:27: note: Revealed type is 'Union[pandas.core.series.Series, None]'
Series_t.py:28: note: Revealed type is 'Union[pandas.core.series.Series, None]'
Series_t.py:29: note: Revealed type is 'Union[pandas.core.series.Series, None]'
Series_t.py:30: note: Revealed type is 'Union[pandas.core.series.Series, None]'
```
> 
> 
> Thanks @LarWong ! Looks good, I just have a question about:
> 
> ```python
> value: Scalar | dict | Series | DataFrame | None
> ```
> 
> Where did you get this from? Was it from inspection? cc @simonjayhawkins is this correct?


@MarcoGorelli For `value`, those were the types suggested by the documentation.