Skip to content

inconsistent behavior of series.last_valid_index, and df.last_valid_index when dataframe empty #12800

Closed
@phil20686

Description

@phil20686
idx = pd.DataFrame().last_valid_index() #throws index error
idx = pd.Series().last_valid_index() #returns None

if you call last_valid_index() on df it throws an IndexError, if you call it on series it returns None. It seems like it would be very little effort to make these two cases consistent. Moreover, I believe they should be consistent with the behavior of

series.get_value(index_value)

where index value is not in the index (i.e. a KeyError).

output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 45 Stepping 7, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.18.0
nose: 1.3.4
pip: 8.1.1
setuptools: 20.2.2
Cython: None
numpy: 1.9.2
scipy: 0.17.0
statsmodels: 0.6.1
xarray: None
IPython: 2.3.0
sphinx: None
patsy: 0.4.1
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.4.2
openpyxl: 2.3.1
xlrd: 0.9.4
xlwt: None
xlsxwriter: 0.8.4
lxml: 3.5.0
bs4: 4.4.1
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.7.3
boto: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions