Skip to content

Commit

Permalink
str accessor (#2991)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0L authored and shoyer committed Jun 10, 2019
1 parent 7e649e4 commit fa55060
Show file tree
Hide file tree
Showing 7 changed files with 1,635 additions and 4 deletions.
10 changes: 10 additions & 0 deletions doc/api.rst
Expand Up @@ -324,6 +324,7 @@ Computation
DataArray.quantile
DataArray.differentiate
DataArray.integrate
DataArray.str

**Aggregation**:
:py:attr:`~DataArray.all`
Expand Down Expand Up @@ -557,6 +558,15 @@ Resample objects also implement the GroupBy interface
core.resample.DatasetResample.nearest
core.resample.DatasetResample.pad

Accessors
=========

.. autosummary::
:toctree: generated/

core.accessor_dt.DatetimeAccessor
core.accessor_str.StringAccessor

Custom Indexes
==============
.. autosummary::
Expand Down
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Expand Up @@ -55,6 +55,8 @@ Enhancements
- Like :py:class:`pandas.DatetimeIndex`, :py:class:`CFTimeIndex` now supports a
:py:meth:`~xarray.CFTimeIndex.strftime` method to return an index of string
formatted datetimes. By `Alan Brammer <https://github.com/abrammer>`_.
- Add ``.str`` accessor to DataArrays for string related manipulations.
By `0x0L <https://github.com/0x0L>`_.

Bug fixes
~~~~~~~~~
Expand Down
6 changes: 3 additions & 3 deletions xarray/core/accessors.py → xarray/core/accessor_dt.py
Expand Up @@ -165,13 +165,13 @@ class DatetimeAccessor:
"""

def __init__(self, xarray_obj):
if not _contains_datetime_like_objects(xarray_obj):
def __init__(self, obj):
if not _contains_datetime_like_objects(obj):
raise TypeError("'dt' accessor only available for "
"DataArray with datetime64 timedelta64 dtype or "
"for arrays containing cftime datetime "
"objects.")
self._obj = xarray_obj
self._obj = obj

def _tslib_field_accessor(name, docstring=None, dtype=None):
def f(self, dtype=dtype):
Expand Down

0 comments on commit fa55060

Please sign in to comment.