Skip to content
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

BUG: pd.fillna(np.nan, inplace=True) replaces values which are not None when using datetime dtype #48863

Closed
2 of 3 tasks
adnapPanda opened this issue Sep 29, 2022 · 2 comments · Fixed by #48866
Closed
2 of 3 tasks
Labels
Bug Datetime Datetime data dtype Regression Functionality that used to work in a prior pandas version replace replace method
Milestone

Comments

@adnapPanda
Copy link

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
import numpy as np

df = pd.DataFrame(
    {
        "date1": pd.to_datetime(["2018-05-30", "2018-06-30", None]),
        "date2": pd.to_datetime(
            [
                None,
                "2018-08-30",
                "2018-09-30",
            ]
        ),
        "date3": pd.to_datetime(
            [
                "2018-08-30",
                None,
                "2018-10-30",
            ]
        ),
    }
)

       date1      date2      date3
0 2018-05-30        NaT 2018-08-30
1 2018-06-30 2018-08-30        NaT
2        NaT 2018-09-30 2018-10-30

df.fillna(np.nan, inplace=True)

       date1      date2      date3
0 2018-05-30        NaT        NaT
1        NaT 2018-08-30        NaT
2        NaT        NaT 2018-10-30

Issue Description

When using the pandas method fillna() and specifying fillna(np.nan, inplace=True), values which are not None are replaced with NaT when using the datetime dtype. When the inplace=True argument is left out and the result of fillna(np.nan) is assigned to a variable, then the expected output is recieved.

Expected Behavior

The expected output is the following:

df.fillna(np.nan, inplace=True)

       date1      date2      date3
0 2018-05-30        NaT 2018-08-30
1 2018-06-30 2018-08-30        NaT
2        NaT 2018-09-30 2018-10-30

Installed Versions

commit : 87cfe4e
python : 3.10.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 151 Stepping 2, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_Netherlands.1252
pandas : 1.5.0
numpy : 1.23.3
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 63.2.0
pip : 22.2.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.6.0
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

@adnapPanda adnapPanda added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 29, 2022
@phofl
Copy link
Member

phofl commented Sep 29, 2022

Hi, thanks for your report.

commit 769fc54897953d366d573d4e45cf13177a5f582b
Author: jbrockmendel <jbrockmendel@gmail.com>
Date:   Thu Feb 10 18:01:53 2022 -0800

    REF: dispatch Block.fillna to putmask/where (#45911)

@phofl phofl added Datetime Datetime data dtype Regression Functionality that used to work in a prior pandas version replace replace method and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 29, 2022
@phofl phofl added this to the 1.5.1 milestone Sep 29, 2022
@MarcoGorelli
Copy link
Member

Hey @adnapPanda

Thanks for having reported this - there's now a release candidate for pandas 2.0.0, which you can install with

mamba install -c conda-forge/label/pandas_rc pandas==2.0.0rc0

or

python -m pip install --upgrade --pre pandas==2.0.0rc0

If you try it out and report bugs, then we can fix them before the final 2.0.0 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Regression Functionality that used to work in a prior pandas version replace replace method
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants