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 using fillna after resample. #16566

Closed
eoincondron opened this issue Jun 1, 2017 · 1 comment
Closed

Bug using fillna after resample. #16566

eoincondron opened this issue Jun 1, 2017 · 1 comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request Resample resample method
Milestone

Comments

@eoincondron
Copy link

Code Sample, a copy-pastable example if possible

df = pd.DataFrame([[1], [2]], DatetimeIndex(['20170101', '20170103']))
df.resample('D').last().fillna(0)
                  0
2017-01-01	1.0
2017-01-02	NaN
2017-01-03	2.0

Problem description

fillna doesn't work as expected for some strange reason here. Multiplying by 1 seems "fix"things:

(1 * df.resample('D').last()).fillna(0)
                  0
2017-01-01	1.0
2017-01-02	0.0
2017-01-03	2.0

but using astype does not

df.resample('D').last().astype(float).fillna(0)
                  0
2017-01-01	1.0
2017-01-02	NaN
2017-01-03	2.0

unless using a mapping

df.resample('D').last().astype({0: float)}.fillna(0)
                  0
2017-01-01	1.0
2017-01-02	0.0
2017-01-03	2.0

isnull gives the expected output:

df.resample('D').last().isnull()
	0
2017-01-01	False
2017-01-02	True
2017-01-03	False

Constructing a the data frame directly gives the expected output:

pd.DataFrame([[1], [np.nan], [2]
    ], pd.DatetimeIndex(['20170101', '20170102', '20170103'], freq='D')).fillna(0)
	0
2017-01-01	1.0
2017-01-02	0.0
2017-01-03	2.0

Expected Output

df = pd.DataFrame([[1], [2]], DatetimeIndex(['20170101', '20170103']))
df.resample('D').last().fillna(0)
0
2017-01-01 1.0
2017-01-02 0.0
2017-01-03 2.0

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 3.10.0-327.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8

pandas: 0.20.1
pytest: 3.0.3
pip: 8.1.2
setuptools: 27.2.0
Cython: None
numpy: 1.12.1
scipy: 0.19.0
xarray: None
IPython: 5.1.0
sphinx: None
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: None
tables: 3.3.0
numexpr: 2.6.2
feather: None
matplotlib: 2.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: 1.0.13
pymysql: 0.7.6.None
psycopg2: None
jinja2: 2.8
s3fs: None
pandas_gbq: None
pandas_datareader: 0.2.1

# Paste the output here pd.show_versions() here
@jreback
Copy link
Contributor

jreback commented Jun 1, 2017

dupe of #16361 and fixed in #16549, will be in 0.20.2 release end-of-week.

@jreback jreback closed this as completed Jun 1, 2017
@jreback jreback added Bug Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request Resample resample method labels Jun 1, 2017
@jreback jreback added this to the 0.20.2 milestone Jun 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request Resample resample method
Projects
None yet
Development

No branches or pull requests

2 participants