Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ Enhancements
- Add ``tolerance`` option to ``resample()`` methods ``bfill``, ``pad``,
``nearest``. (:issue:`2695`)
By `Hauke Schulz <https://github.com/observingClouds>`_.

- :py:meth:`~xarray.DataArray.integrate` and
:py:meth:`~xarray.Dataset.integrate` are newly added.
See :ref:`_compute.using_coordinates` for the detail.
(:issue:`1332`)
By `Keisuke Fujii <https://github.com/fujiisoup>`_.

- :py:meth:`pandas.Series.dropna` is now supported for a
:py:class:`pandas.Series` indexed by a :py:class:`~xarray.CFTimeIndex`
(:issue:`2688`). By `Spencer Clark <https://github.com/spencerkclark>`_.

Bug fixes
~~~~~~~~~
Expand Down
8 changes: 5 additions & 3 deletions xarray/coding/cftimeindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,13 @@ def _maybe_cast_slice_bound(self, label, side, kind):
# e.g. series[1:5].
def get_value(self, series, key):
"""Adapted from pandas.tseries.index.DatetimeIndex.get_value"""
if not isinstance(key, slice):
return series.iloc[self.get_loc(key)]
else:
if np.asarray(key).dtype is np.dtype(bool):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use == instead of is -- in theory np.dtype() could return new dtype objects.

return series.iloc[key]
elif isinstance(key, slice):
return series.iloc[self.slice_indexer(
key.start, key.stop, key.step)]
else:
return series.iloc[self.get_loc(key)]

def __contains__(self, key):
"""Adapted from
Expand Down
8 changes: 8 additions & 0 deletions xarray/tests/test_cftimeindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,14 @@ def test_indexing_in_series_iloc(series, index):
assert series.iloc[:2].equals(expected)


@pytest.mark.skipif(not has_cftime, reason='cftime not installed')
def test_series_dropna(index):
series = pd.Series([0., 1., np.nan, np.nan], index=index)
expected = series.iloc[:2]
result = series.dropna()
assert result.equals(expected)


@pytest.mark.skipif(not has_cftime, reason='cftime not installed')
def test_indexing_in_dataframe_loc(df, index, scalar_args, range_args):
expected = pd.Series([1], name=index[0])
Expand Down