Skip to content

ENH: str accessor #2991

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

Merged
merged 1 commit into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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
Original file line number Diff line number Diff line change
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
Loading