Skip to content

BUG: None is replaced with Nan #43721

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

Closed
2 of 3 tasks
George3d6 opened this issue Sep 23, 2021 · 2 comments
Closed
2 of 3 tasks

BUG: None is replaced with Nan #43721

George3d6 opened this issue Sep 23, 2021 · 2 comments
Labels
Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Usage Question

Comments

@George3d6
Copy link

George3d6 commented Sep 23, 2021

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

  • I have confirmed this bug exists on the latest version of pandas.
    Note: Env bellow is not the latest, but I also tested with 1.3.3 and behavior remains the same

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

Reproducible Example

import pandas as pd
df = pd.DataFrame()
df['a'] = [1,2,3,4,5,6,7,8,None,None]
print(df['a'])

> Outputs:
0    1.0
1    2.0
2    3.0
3    4.0
4    5.0
5    6.0
6    7.0
7    8.0
8    NaN
9    NaN
Name: a, dtype: float64

Issue Description

Pandas is replacing None with NaN these are no the same, this is horrible and will cause bugs

Expected Behavior

I'd expected values I assign to an element or column in a pandas data frame to either:

  1. Get assigned
  2. Raise and error if they can't be assigned

Installed Versions

pd.show_versions()

INSTALLED VERSIONS

commit : 67a3d42
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.11.0-34-generic
Version : #36~20.04.1-Ubuntu SMP Fri Aug 27 08:06:32 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8

pandas : 1.1.4
numpy : 1.21.2
pytz : 2019.3
dateutil : 2.7.3
pip : 20.0.2
setuptools : 57.4.0
Cython : 0.29.21
pytest : 6.1.2
hypothesis : None
sphinx : 4.1.2
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.18.1
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : 0.8.7
fastparquet : None
gcsfs : None
matplotlib : 3.3.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 4.0.0
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.7.0
sqlalchemy : 1.4.23
tables : None
tabulate : 0.8.7
xarray : None
xlrd : 1.2.0
xlwt : None
numba : 0.53.1

@George3d6 George3d6 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 23, 2021
@jreback
Copy link
Contributor

jreback commented Sep 23, 2021

https://pandas.pydata.org/docs/dev/user_guide/missing_data.html

None is an object snd cannot be represented as such in a numeric array

you can use object dtype and it will preserve with a performance penalty

@jreback jreback added Usage Question Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 23, 2021
@jreback jreback added this to the No action milestone Sep 23, 2021
@jreback jreback closed this as completed Sep 23, 2021
@George3d6
Copy link
Author

But converting to object doesn't actually work in most cases.

Pandas randomly decide to convert object typed column backed into ints and there's no reliable way to "force" it to use object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Usage Question
Projects
None yet
Development

No branches or pull requests

2 participants