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: Series.asof fails when series is all nans #15713

Closed
adbull opened this issue Mar 17, 2017 · 3 comments
Closed

BUG: Series.asof fails when series is all nans #15713

adbull opened this issue Mar 17, 2017 · 3 comments
Labels
Bug Datetime Datetime data dtype Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@adbull
Copy link
Contributor

adbull commented Mar 17, 2017

Code Sample, a copy-pastable example if possible

>>> import pandas as pd
>>> import numpy as np
>>> pd.Series([np.nan]).asof([0])
Traceback (most recent call last):
  File "<ipython-input-268-2b0f8084a393>", line 1, in <module>
    pd.Series([np.nan]).asof([0])
  File "~/anaconda3/lib/python3.5/site-packages/pandas/core/generic.py", line 3985, in asof
    locs = self.index.asof_locs(where, ~(nulls.values))
  File "~/anaconda3/lib/python3.5/site-packages/pandas/indexes/base.py", line 1837, in asof_locs
    result = np.arange(len(self))[mask].take(locs)
IndexError: cannot do a non-empty take from an empty axes.

Problem description

When calling Series.asof(), if the series happens to contain all nans, an error is raised. See #10343.

Expected Output

0   NaN
dtype: float64

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.9.8-100.fc24.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: C
LANG: C
LOCALE: None.None

pandas: 0.19.0+579.g4ce9c0c
pytest: 3.0.5
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.11.3
scipy: 0.18.1
xarray: 0.9.1
IPython: 4.2.0
sphinx: 1.5.1
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: 1.2.0
tables: 3.3.0
numexpr: 2.6.2
feather: None
matplotlib: 2.0.0
openpyxl: 2.4.1
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.2
bs4: 4.5.3
html5lib: 0.999
sqlalchemy: 1.1.5
pymysql: None
psycopg2: None
jinja2: 2.9.4
s3fs: None
pandas_gbq: None
pandas_datareader: None

@jreback
Copy link
Contributor

jreback commented Mar 17, 2017

ok, this is a pretty trivial fix. PR's are welcome.

@jreback jreback added Bug Difficulty Novice Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Datetime Datetime data dtype labels Mar 17, 2017
@jreback jreback added this to the Next Major Release milestone Mar 17, 2017
@ucals
Copy link

ucals commented Mar 20, 2017

I'd like to start contributing and try this one

ucals pushed a commit to ucals/pandas that referenced this issue Mar 21, 2017
ucals pushed a commit to ucals/pandas that referenced this issue Mar 21, 2017
ucals pushed a commit to ucals/pandas that referenced this issue Mar 21, 2017
ucals pushed a commit to ucals/pandas that referenced this issue Mar 21, 2017
@jreback jreback modified the milestones: 0.20.0, Next Major Release Mar 23, 2017
jreback pushed a commit that referenced this issue Mar 26, 2017
closes bug #15713

Added the test if the series is all nans  Added the code that check if
that's the case: if yes, return the expected output

Author: Carlos Souza <carlos@udacity.com>

Closes #15758 from ucals/bug-fix-15713 and squashes the following commits:

0765108 [Carlos Souza] First simplification, code-block in the same place
bb63964 [Carlos Souza] Propagating Series name
af9a29b [Carlos Souza] Setting name of asof result when scalar input and all nan
b8f078a [Carlos Souza] Small code standard change
7448b96 [Carlos Souza] Fixing scalar input
a080b9b [Carlos Souza] Making scalar input return in a Series
04b7306 [Carlos Souza] Removing .values and formating code PEP8
3f9c7fd [Carlos Souza] Minor comments
70c958f [Carlos Souza] Added tests for non-default indexes, scalar and multiple inputs, and results preserve columns
6b745af [Carlos Souza] Adding DataFrame tests & support, and optimizing the code
89fb6cf [Carlos Souza] BUG #15713 fixing failing tests
17d1d77 [Carlos Souza] BUG #15713 Series.asof return nan when series is all nans!
4e26ab8 [Carlos Souza] BUG #15713 Series.asof return nan when series is all nans.
c78d687 [Carlos Souza] BUG #15713 Series.asof return nan when series is all nans
676a4e5 [Carlos Souza] Test
@jreback
Copy link
Contributor

jreback commented Mar 29, 2017

closed by #15758

@jreback jreback closed this as completed Mar 29, 2017
mattip pushed a commit to mattip/pandas that referenced this issue Apr 3, 2017
closes bug pandas-dev#15713

Added the test if the series is all nans  Added the code that check if
that's the case: if yes, return the expected output

Author: Carlos Souza <carlos@udacity.com>

Closes pandas-dev#15758 from ucals/bug-fix-15713 and squashes the following commits:

0765108 [Carlos Souza] First simplification, code-block in the same place
bb63964 [Carlos Souza] Propagating Series name
af9a29b [Carlos Souza] Setting name of asof result when scalar input and all nan
b8f078a [Carlos Souza] Small code standard change
7448b96 [Carlos Souza] Fixing scalar input
a080b9b [Carlos Souza] Making scalar input return in a Series
04b7306 [Carlos Souza] Removing .values and formating code PEP8
3f9c7fd [Carlos Souza] Minor comments
70c958f [Carlos Souza] Added tests for non-default indexes, scalar and multiple inputs, and results preserve columns
6b745af [Carlos Souza] Adding DataFrame tests & support, and optimizing the code
89fb6cf [Carlos Souza] BUG pandas-dev#15713 fixing failing tests
17d1d77 [Carlos Souza] BUG pandas-dev#15713 Series.asof return nan when series is all nans!
4e26ab8 [Carlos Souza] BUG pandas-dev#15713 Series.asof return nan when series is all nans.
c78d687 [Carlos Souza] BUG pandas-dev#15713 Series.asof return nan when series is all nans
676a4e5 [Carlos Souza] Test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

No branches or pull requests

3 participants