From 1569225c731dcbb9a2be1bd1ef3623c2d8ed5e9d Mon Sep 17 00:00:00 2001 From: remigathoni Date: Tue, 14 Mar 2023 20:04:58 +0300 Subject: [PATCH 01/44] Use more descriptive link texts --- doc/contributing.rst | 17 ++++++++--------- doc/developers-meeting.rst | 4 ++-- doc/user-guide/computation.rst | 2 +- doc/user-guide/dask.rst | 12 ++++++------ doc/user-guide/groupby.rst | 9 +++------ doc/user-guide/indexing.rst | 12 ++++++------ doc/user-guide/io.rst | 16 ++++++++-------- doc/user-guide/pandas.rst | 6 +++--- doc/user-guide/time-series.rst | 4 ++-- doc/user-guide/weather-climate.rst | 6 +++--- 10 files changed, 42 insertions(+), 46 deletions(-) diff --git a/doc/contributing.rst b/doc/contributing.rst index a69a8017110..3e62d1a8284 100644 --- a/doc/contributing.rst +++ b/doc/contributing.rst @@ -35,8 +35,8 @@ Bug reports and enhancement requests Bug reports are an important part of making *xarray* more stable. Having a complete bug report will allow others to reproduce the bug and provide insight into fixing. See -`this stackoverflow article `_ for tips on -writing a good bug report. +this `stackoverflow article for tips on +writing a good bug report `_ . Trying out the bug-producing code on the *main* branch is often a worthwhile exercise to confirm that the bug still exists. It is also worth searching existing bug reports and @@ -102,7 +102,7 @@ Some great resources for learning Git: Getting started with Git ------------------------ -`GitHub has instructions `__ for installing git, +`GitHub has instructions for setting up Git `__ including installing git, setting up your SSH key, and configuring git. All these steps need to be completed before you can work seamlessly between your local repository and GitHub. @@ -238,7 +238,7 @@ To return to your root environment:: conda deactivate -See the full conda docs `here `__. +See the full `conda docs here `__. .. _contributing.documentation: @@ -277,7 +277,7 @@ Some other important things to know about the docs: - The docstrings follow the **NumPy Docstring Standard**, which is used widely in the Scientific Python community. This standard specifies the format of - the different sections of the docstring. See `this document + the different sections of the docstring. Refer to the `documentation for the Numpy docstring format `_ for a detailed explanation, or look at some of the existing functions to extend it in a similar manner. @@ -732,8 +732,8 @@ or, to use a specific Python interpreter,:: This will display stderr from the benchmarks, and use your local ``python`` that comes from your ``$PATH``. -Information on how to write a benchmark and how to use asv can be found in the -`asv documentation `_. +Learn `how to write a benchmark and how to use asv from the documentayion `_ . + .. TODO: uncomment once we have a working setup @@ -752,8 +752,7 @@ GitHub issue number when adding your entry (using ``:issue:`1234```, where ``123 issue/pull request number). If your code is an enhancement, it is most likely necessary to add usage -examples to the existing documentation. This can be done following the section -regarding documentation :ref:`above `. +examples to the existing documentation. This can be done by following the :ref:`guidelines for contributing to the documentation `. .. _contributing.changes: diff --git a/doc/developers-meeting.rst b/doc/developers-meeting.rst index ff706b17af8..1c49a900f66 100644 --- a/doc/developers-meeting.rst +++ b/doc/developers-meeting.rst @@ -5,9 +5,9 @@ Xarray developers meet bi-weekly every other Wednesday. The meeting occurs on `Zoom `__. -Notes for the meeting are kept `here `__. +Find the `notes for the meeting here `__. -There is a :issue:`GitHub issue <4001>` for changes to the meeting. +There is a :issue:`GitHub issue for changes to the meeting<4001>`. You can subscribe to this calendar to be notified of changes: diff --git a/doc/user-guide/computation.rst b/doc/user-guide/computation.rst index b9a54dce1bf..f913ea41a91 100644 --- a/doc/user-guide/computation.rst +++ b/doc/user-guide/computation.rst @@ -804,7 +804,7 @@ to set ``axis=-1``. As an example, here is how we would wrap Because ``apply_ufunc`` follows a standard convention for ufuncs, it plays nicely with tools for building vectorized functions, like :py:func:`numpy.broadcast_arrays` and :py:class:`numpy.vectorize`. For high performance -needs, consider using Numba's :doc:`vectorize and guvectorize `. +needs, consider using :doc:`Numba's vectorize and guvectorize `. In addition to wrapping functions, ``apply_ufunc`` can automatically parallelize many functions when using dask by setting ``dask='parallelized'``. See diff --git a/doc/user-guide/dask.rst b/doc/user-guide/dask.rst index de8fcd84c8b..5c1899dc484 100644 --- a/doc/user-guide/dask.rst +++ b/doc/user-guide/dask.rst @@ -39,7 +39,7 @@ The actual computation is controlled by a multi-processing or thread pool, which allows Dask to take full advantage of multiple processors available on most modern computers. -For more details on Dask, read `its documentation `__. +For more details, read the `Dask documentation `__. Note that xarray only makes use of ``dask.array`` and ``dask.delayed``. .. _dask.io: @@ -234,7 +234,7 @@ disk. .. note:: For more on the differences between :py:meth:`~xarray.Dataset.persist` and - :py:meth:`~xarray.Dataset.compute` see this `Stack Overflow answer `_ and the `Dask documentation `_. + :py:meth:`~xarray.Dataset.compute` see this `Stack Overflow answer on the differences between client persist and client compute `_ and the `Dask documentation `_. For performance you may wish to consider chunk sizes. The correct choice of chunk size depends both on your data and on the operations you want to perform. @@ -549,7 +549,7 @@ larger chunksizes. .. tip:: - Check out the dask documentation on `chunks `_. + Check out the `dask documentation of chunks `_. Optimization Tips @@ -562,7 +562,7 @@ through experience: 1. Do your spatial and temporal indexing (e.g. ``.sel()`` or ``.isel()``) early in the pipeline, especially before calling ``resample()`` or ``groupby()``. Grouping and resampling triggers some computation on all the blocks, which in theory should commute with indexing, but this optimization hasn't been implemented in Dask yet. (See `Dask issue #746 `_). 2. More generally, ``groupby()`` is a costly operation and will perform a lot better if the ``flox`` package is installed. - See the `flox documentation `_ for more. By default Xarray will use ``flox`` if installed. + See the `flox documentation `_ for more. By default Xarray will use ``flox`` if installed. 3. Save intermediate results to disk as a netCDF files (using ``to_netcdf()``) and then load them again with ``open_dataset()`` for further computations. For example, if subtracting temporal mean from a dataset, save the temporal mean to disk before subtracting. Again, in theory, Dask should be able to do the computation in a streaming fashion, but in practice this is a fail case for the Dask scheduler, because it tries to keep every chunk of an array that it computes in memory. (See `Dask issue #874 `_) @@ -572,6 +572,6 @@ through experience: 6. Using the h5netcdf package by passing ``engine='h5netcdf'`` to :py:meth:`~xarray.open_mfdataset` can be quicker than the default ``engine='netcdf4'`` that uses the netCDF4 package. -7. Some dask-specific tips may be found `here `_. +7. Find `best practices specific to Dask arrays in the documentation `_. -8. The dask `diagnostics `_ can be useful in identifying performance bottlenecks. +8. The `dask diagnostics `_ can be useful in identifying performance bottlenecks. diff --git a/doc/user-guide/groupby.rst b/doc/user-guide/groupby.rst index c5a071171a6..d24a79a98cf 100644 --- a/doc/user-guide/groupby.rst +++ b/doc/user-guide/groupby.rst @@ -25,12 +25,9 @@ the same pipeline. .. tip:: To substantially improve the performance of GroupBy operations, particularly - with dask install the `flox `_ package. flox also - `extends `_ - Xarray's in-built GroupBy capabilities by allowing grouping by multiple variables, - and lazy grouping by dask arrays. Xarray will automatically use flox by default - if it is installed. - + with dask `install the flox package `_. flox + `extends Xarray's in-built GroupBy capabilities `_ + by allowing grouping by multiple variables, and lazy grouping by dask arrays. If installed, Xarray will automatically use flox by default. Split ~~~~~ diff --git a/doc/user-guide/indexing.rst b/doc/user-guide/indexing.rst index e0337f24b9b..492316f898f 100644 --- a/doc/user-guide/indexing.rst +++ b/doc/user-guide/indexing.rst @@ -95,7 +95,7 @@ In this example, the selected is a subpart of the array in the range '2000-01-01':'2000-01-02' along the first coordinate `time` and with 'IA' value from the second coordinate `space`. -You can perform any of the label indexing operations `supported by pandas`__, +You can perform any of the `label indexing operations supported by pandas`__, including indexing with individual, slices and lists/arrays of labels, as well as indexing with boolean arrays. Like pandas, label based indexing in xarray is *inclusive* of both the start and stop bounds. @@ -140,14 +140,14 @@ use them explicitly to slice data. There are two ways to do this: The arguments to these methods can be any objects that could index the array along the dimension given by the keyword, e.g., labels for an individual value, -Python :py:class:`slice` objects or 1-dimensional arrays. +:py:class:`Python slice` objects or 1-dimensional arrays. .. note:: We would love to be able to do indexing with labeled dimension names inside - brackets, but unfortunately, Python `does yet not support`__ indexing with - keyword arguments like ``da[space=0]`` + brackets, but unfortunately, `Python does not yet support indexing with + keyword arguments`__ like ``da[space=0]`` __ https://legacy.python.org/dev/peps/pep-0472/ @@ -372,12 +372,12 @@ indexers' dimension: ind = xr.DataArray([[0, 1], [0, 1]], dims=["a", "b"]) da[ind] -Similar to how NumPy's `advanced indexing`_ works, vectorized +Similar to how `NumPy's advanced indexing`_ works, vectorized indexing for xarray is based on our :ref:`broadcasting rules `. See :ref:`indexing.rules` for the complete specification. -.. _advanced indexing: https://numpy.org/doc/stable/reference/arrays.indexing.html +.. _NumPy's advanced indexing: https://numpy.org/doc/stable/reference/arrays.indexing.html Vectorized indexing also works with ``isel``, ``loc``, and ``sel``: diff --git a/doc/user-guide/io.rst b/doc/user-guide/io.rst index 9e5d7ad71a3..0594f63193f 100644 --- a/doc/user-guide/io.rst +++ b/doc/user-guide/io.rst @@ -684,9 +684,9 @@ instance and pass this, as follows: Zarr Compressors and Filters ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -There are many different options for compression and filtering possible with -zarr. These are described in the -`zarr documentation `_. +There are many different `options for compression and filtering possible with +zarr `_. + These options can be passed to the ``to_zarr`` method as variable encoding. For example: @@ -720,7 +720,7 @@ As of xarray version 0.18, xarray by default uses a feature called *consolidated metadata*, storing all metadata for the entire dataset with a single key (by default called ``.zmetadata``). This typically drastically speeds up opening the store. (For more information on this feature, consult the -`zarr docs `_.) +`zarr docs on consolidating metadata `_.) By default, xarray writes consolidated metadata and attempts to read stores with consolidated metadata, falling back to use non-consolidated metadata for @@ -1165,7 +1165,7 @@ rasterio is installed. Here is an example of how to use Deprecated in favor of rioxarray. For information about transitioning, see: - https://corteva.github.io/rioxarray/stable/getting_started/getting_started.html + `rioxarray getting started docs`` .. ipython:: :verbatim: @@ -1277,7 +1277,7 @@ Formats supported by PyNIO .. warning:: - The PyNIO backend is deprecated_. PyNIO is no longer maintained_. See + The `PyNIO backend is deprecated`_. `PyNIO is no longer maintained`_. Xarray can also read GRIB, HDF4 and other file formats supported by PyNIO_, if PyNIO is installed. To use PyNIO to read such files, supply @@ -1288,8 +1288,8 @@ We recommend installing PyNIO via conda:: conda install -c conda-forge pynio .. _PyNIO: https://www.pyngl.ucar.edu/Nio.shtml -.. _deprecated: https://github.com/pydata/xarray/issues/4491 -.. _maintained: https://github.com/NCAR/pynio/issues/53 +.. _PyNIO backend is deprecated: https://github.com/pydata/xarray/issues/4491 +.. _PyNIO is no longer maintained: https://github.com/NCAR/pynio/issues/53 .. _io.PseudoNetCDF: diff --git a/doc/user-guide/pandas.rst b/doc/user-guide/pandas.rst index a376b0a5cb8..76349fcd371 100644 --- a/doc/user-guide/pandas.rst +++ b/doc/user-guide/pandas.rst @@ -8,7 +8,7 @@ Working with pandas One of the most important features of xarray is the ability to convert to and from :py:mod:`pandas` objects to interact with the rest of the PyData ecosystem. For example, for plotting labeled data, we highly recommend -using the visualization `built in to pandas itself`__ or provided by the pandas +using the `visualization built in to pandas itself`__ or provided by the pandas aware libraries such as `Seaborn`__. __ https://pandas.pydata.org/pandas-docs/stable/visualization.html @@ -168,7 +168,7 @@ multi-dimensional arrays to xarray. Xarray has most of ``Panel``'s features, a more explicit API (particularly around indexing), and the ability to scale to >3 dimensions with the same interface. -As discussed :ref:`elsewhere ` in the docs, there are two primary data structures in +As discussed in the :ref:`data structures section of the docs `, there are two primary data structures in xarray: ``DataArray`` and ``Dataset``. You can imagine a ``DataArray`` as a n-dimensional pandas ``Series`` (i.e. a single typed array), and a ``Dataset`` as the ``DataFrame`` equivalent (i.e. a dict of aligned ``DataArray`` objects). @@ -240,6 +240,6 @@ While the xarray docs are relatively complete, a few items stand out for Panel u the Person dimension of a Dataset of Person x Score x Time. While xarray may take some getting used to, it's worth it! If anything is unclear, -please post an issue on `GitHub `__ or +please `post an issue on GitHub `__ or `StackOverflow `__, and we'll endeavor to respond to the specific case or improve the general docs. diff --git a/doc/user-guide/time-series.rst b/doc/user-guide/time-series.rst index 90ec4cb32be..4956e8b5dec 100644 --- a/doc/user-guide/time-series.rst +++ b/doc/user-guide/time-series.rst @@ -108,10 +108,10 @@ For more details, read the pandas documentation and the section on :ref:`datetim Datetime components ------------------- -Similar `to pandas`_, the components of datetime objects contained in a +Similar to `pandas accessors`_, the components of datetime objects contained in a given ``DataArray`` can be quickly computed using a special ``.dt`` accessor. -.. _to pandas: https://pandas.pydata.org/pandas-docs/stable/basics.html#basics-dt-accessors +.. _pandas accessor: https://pandas.pydata.org/pandas-docs/stable/basics.html#basics-dt-accessors .. ipython:: python diff --git a/doc/user-guide/weather-climate.rst b/doc/user-guide/weather-climate.rst index 793da9d1bdd..30876eb36bc 100644 --- a/doc/user-guide/weather-climate.rst +++ b/doc/user-guide/weather-climate.rst @@ -10,7 +10,7 @@ Weather and climate data import xarray as xr -Xarray can leverage metadata that follows the `Climate and Forecast (CF) conventions`_ if present. Examples include automatic labelling of plots with descriptive names and units if proper metadata is present (see :ref:`plotting`) and support for non-standard calendars used in climate science through the ``cftime`` module (see :ref:`CFTimeIndex`). There are also a number of geosciences-focused projects that build on xarray (see :ref:`ecosystem`). +Xarray can leverage metadata that follows the `Climate and Forecast (CF) conventions`_ if present. Examples include :ref:`automatic labelling of plots` with descriptive names and units if proper metadata is present and support for non-standard calendars used in climate science through the ``cftime`` module(Explained in the :ref:`CFTimeIndex` section). There are also a number of :ref:`geosciences-focused projects that build on xarray`. .. _Climate and Forecast (CF) conventions: https://cfconventions.org @@ -49,10 +49,10 @@ variable with the attribute, rather than with the dimensions. CF-compliant coordinate variables --------------------------------- -`MetPy`_ adds a ``metpy`` accessor that allows accessing coordinates with appropriate CF metadata using generic names ``x``, ``y``, ``vertical`` and ``time``. There is also a `cartopy_crs` attribute that provides projection information, parsed from the appropriate CF metadata, as a `Cartopy`_ projection object. See `their documentation`_ for more information. +`MetPy`_ adds a ``metpy`` accessor that allows accessing coordinates with appropriate CF metadata using generic names ``x``, ``y``, ``vertical`` and ``time``. There is also a `cartopy_crs` attribute that provides projection information, parsed from the appropriate CF metadata, as a `Cartopy`_ projection object. See the `metpy documentation`_ for more information. .. _`MetPy`: https://unidata.github.io/MetPy/dev/index.html -.. _`their documentation`: https://unidata.github.io/MetPy/dev/tutorials/xarray_tutorial.html#coordinates +.. _`metpy documentation`: https://unidata.github.io/MetPy/dev/tutorials/xarray_tutorial.html#coordinates .. _`Cartopy`: https://scitools.org.uk/cartopy/docs/latest/crs/projections.html .. _CFTimeIndex: From 78fc1005ef3c68ccafa30a4baa3c1870275b2243 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 Mar 2023 17:11:13 +0000 Subject: [PATCH 02/44] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- doc/user-guide/groupby.rst | 2 +- doc/user-guide/io.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/user-guide/groupby.rst b/doc/user-guide/groupby.rst index d24a79a98cf..dce20dce228 100644 --- a/doc/user-guide/groupby.rst +++ b/doc/user-guide/groupby.rst @@ -26,7 +26,7 @@ the same pipeline. To substantially improve the performance of GroupBy operations, particularly with dask `install the flox package `_. flox - `extends Xarray's in-built GroupBy capabilities `_ + `extends Xarray's in-built GroupBy capabilities `_ by allowing grouping by multiple variables, and lazy grouping by dask arrays. If installed, Xarray will automatically use flox by default. Split diff --git a/doc/user-guide/io.rst b/doc/user-guide/io.rst index 0594f63193f..5610e7829f2 100644 --- a/doc/user-guide/io.rst +++ b/doc/user-guide/io.rst @@ -685,7 +685,7 @@ Zarr Compressors and Filters ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ There are many different `options for compression and filtering possible with -zarr `_. +zarr `_. These options can be passed to the ``to_zarr`` method as variable encoding. For example: From 62a98847665cbb93231259df13d016f7080f7d17 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Tue, 14 Mar 2023 20:17:36 +0300 Subject: [PATCH 03/44] Fix link target name --- doc/user-guide/time-series.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/user-guide/time-series.rst b/doc/user-guide/time-series.rst index 4956e8b5dec..d2e15adeba7 100644 --- a/doc/user-guide/time-series.rst +++ b/doc/user-guide/time-series.rst @@ -111,7 +111,7 @@ Datetime components Similar to `pandas accessors`_, the components of datetime objects contained in a given ``DataArray`` can be quickly computed using a special ``.dt`` accessor. -.. _pandas accessor: https://pandas.pydata.org/pandas-docs/stable/basics.html#basics-dt-accessors +.. _pandas accessors: https://pandas.pydata.org/pandas-docs/stable/basics.html#basics-dt-accessors .. ipython:: python From 84de8b146f6ea5629580ec85d70fbb5ad3786213 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Thu, 16 Mar 2023 20:56:30 +0300 Subject: [PATCH 04/44] Fix typos --- doc/contributing.rst | 2 +- doc/user-guide/dask.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/contributing.rst b/doc/contributing.rst index 3e62d1a8284..07938f23c9f 100644 --- a/doc/contributing.rst +++ b/doc/contributing.rst @@ -732,7 +732,7 @@ or, to use a specific Python interpreter,:: This will display stderr from the benchmarks, and use your local ``python`` that comes from your ``$PATH``. -Learn `how to write a benchmark and how to use asv from the documentayion `_ . +Learn `how to write a benchmark and how to use asv from the documentation `_ . .. diff --git a/doc/user-guide/dask.rst b/doc/user-guide/dask.rst index 5c1899dc484..27e7449b7c3 100644 --- a/doc/user-guide/dask.rst +++ b/doc/user-guide/dask.rst @@ -549,7 +549,7 @@ larger chunksizes. .. tip:: - Check out the `dask documentation of chunks `_. + Check out the `dask documentation on chunks `_. Optimization Tips From e041718d637def7678dda20617ea011d40da20b0 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Fri, 24 Mar 2023 07:46:18 +0300 Subject: [PATCH 05/44] Add example for DataArray.str.capitalize --- xarray/core/accessor_str.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 16e22ec1c66..90ccc0df27f 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -672,6 +672,14 @@ def capitalize(self) -> T_DataArray: Returns ------- capitalized : same type as values + + Example + ------- + >>> da = xr.DataArray(['temperature', 'pressure'], dims="item") + >>> da + array(['temperature', 'pressure'], dtype='>> da.str.capitalize() + array(['Temperature', 'Pressure'], dtype=' Date: Fri, 24 Mar 2023 07:53:05 +0300 Subject: [PATCH 06/44] Add example for DataArray.str.lower --- xarray/core/accessor_str.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 90ccc0df27f..975ada7c956 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -690,6 +690,14 @@ def lower(self) -> T_DataArray: Returns ------- lowerd : same type as values + + Example + ------- + >>> da = xr.DataArray(['Temperature', 'PRESSURE'], dims="item") + >>> da + array(['Temperature', 'PRESSURE'], dtype='>> da.str.lower() + array(['temperature', 'pressure'], dtype=' Date: Fri, 24 Mar 2023 08:05:08 +0300 Subject: [PATCH 07/44] Add docstring example for DataArray.str.swapcase --- xarray/core/accessor_str.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 975ada7c956..a980d48ad00 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -708,6 +708,14 @@ def swapcase(self) -> T_DataArray: Returns ------- swapcased : same type as values + + Example + ------- + >>> da = xr.DataArray(['temperature', 'PRESSURE', 'HuMiDiTy'], dims="item") + >>> da + array(['temperature', 'PRESSURE', 'HuMiDiTy'], dtype='>> da.str.swapcase() + array(['TEMPERATURE', 'pressure', 'hUmIdItY'], dtype=' Date: Fri, 24 Mar 2023 08:37:10 +0300 Subject: [PATCH 08/44] Add docstring example for DataArray.str.title --- xarray/core/accessor_str.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index a980d48ad00..7a6986a0059 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -726,6 +726,14 @@ def title(self) -> T_DataArray: Returns ------- titled : same type as values + + Example + ------- + >>> da = xr.DataArray(['temperature', 'PRESSURE', 'HuMiDiTy'], dims="item") + >>> da + array(['temperature', 'PRESSURE', 'HuMiDiTy'], dtype='>> da.str.title() + array(['Temperature', 'Pressure', 'Humidity'], dtype=' Date: Fri, 24 Mar 2023 08:38:51 +0300 Subject: [PATCH 09/44] Add docstring example for DataArray.str.upper --- xarray/core/accessor_str.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 7a6986a0059..c82565307f2 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -744,6 +744,14 @@ def upper(self) -> T_DataArray: Returns ------- uppered : same type as values + + Example + ------- + >>> da = xr.DataArray(['temperature', 'HuMiDiTy'], dims="item") + >>> da + array(['temperature', 'HuMiDiTy'], dtype='>> da.str.upper() + array(['TEMPERATURE', 'HUMIDITY'], dtype=' Date: Fri, 24 Mar 2023 08:54:51 +0300 Subject: [PATCH 10/44] Add docstring example for DataArray.str.casefold --- xarray/core/accessor_str.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index c82565307f2..b8b093868e6 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -762,11 +762,27 @@ def casefold(self) -> T_DataArray: Casefolding is similar to converting to lowercase, but removes all case distinctions. This is important in some languages that have more complicated - cases and case conversions. + cases and case conversions. For example, + the 'ß' character in German is case-folded to 'ss', whereas it is lowercased + to 'ß'. Returns ------- casefolded : same type as values + + Examples + -------- + >>> da = xr.DataArray(['TEMPERATURE', 'HuMiDiTy'], dims="item") + >>> da + array(['TEMPERATURE', 'HuMiDiTy'], dtype='>> da.str.casefold() + array(['temperature', 'humidity'], dtype='>> da = xr.DataArray(['ß', 'İ'], dims='x') + >>> da + array(['ß', 'İ'], dtype='>> da.str.casefold() + array(['ss', 'i̇'], dtype=' Date: Fri, 24 Mar 2023 09:01:19 +0300 Subject: [PATCH 11/44] Add docstring example for DataArray.str.isalnum --- xarray/core/accessor_str.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index b8b093868e6..bc129a4c55b 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -816,6 +816,14 @@ def isalnum(self) -> T_DataArray: ------- isalnum : array of bool Array of boolean values with the same shape as the original array. + + Example + ------- + >>> da = xr.DataArray(['H2O', 'NaCl-'], dims='x') + >>> da + array(['H2O', 'NaCl-'], dtype='>> da.str.isalnum() + array([ True, False]) """ return self._apply(func=lambda x: x.isalnum(), dtype=bool) From 938e1f89f3d53a51c5955459ea6d6f0d28688471 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Fri, 24 Mar 2023 09:03:35 +0300 Subject: [PATCH 12/44] Add docstring example for DataArray.str.isalpha --- xarray/core/accessor_str.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index bc129a4c55b..689a97508ef 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -835,6 +835,14 @@ def isalpha(self) -> T_DataArray: ------- isalpha : array of bool Array of boolean values with the same shape as the original array. + + Example + ------- + >>> da = xr.DataArray(['Mn' 'H2O', 'NaCl-'], dims='x') + >>> da + array(['Mn', 'H2O', 'NaCl-'], dtype='>> da.str.isalpha() + array([ True, False, False]) """ return self._apply(func=lambda x: x.isalpha(), dtype=bool) From d58c5d2bd7b69a18d55039da79a4354d2b35abf4 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Fri, 24 Mar 2023 09:10:27 +0300 Subject: [PATCH 13/44] Add docstring example for DataArray.str.isdecimal --- xarray/core/accessor_str.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 689a97508ef..0523c1b4233 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -854,6 +854,14 @@ def isdecimal(self) -> T_DataArray: ------- isdecimal : array of bool Array of boolean values with the same shape as the original array. + + Example + ------- + >>> da = xr.DataArray(['2.3', '123', '0'], dims='x') + >>> da + array(['2.3', '123', '0'], dtype='>> da.str.isdecimal() + array([False, True, True]) """ return self._apply(func=lambda x: x.isdecimal(), dtype=bool) From 83f105f123ef161f3903f42db165b9c8ea57d32f Mon Sep 17 00:00:00 2001 From: remigathoni Date: Fri, 24 Mar 2023 09:17:08 +0300 Subject: [PATCH 14/44] Add docstring example for DataArray.str.isdigit --- xarray/core/accessor_str.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 0523c1b4233..47253224bb7 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -873,6 +873,14 @@ def isdigit(self) -> T_DataArray: ------- isdigit : array of bool Array of boolean values with the same shape as the original array. + + Example + ------- + >>> da = xr.DataArray(['123', '1.2', '0', 'CO2', 'NaCl'], dims='x') + >>> da + array(['123', '1.2', '0', 'CO2', 'NaCl'], dtype='>> da.str.isdigit() + array([ True, False, True, False, False]) """ return self._apply(func=lambda x: x.isdigit(), dtype=bool) From 23c0c6c8873ed3e7f4edd15fe78973103f8a2ef0 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Fri, 24 Mar 2023 09:25:52 +0300 Subject: [PATCH 15/44] Add docstring example for DataArray.str.islower --- xarray/core/accessor_str.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 47253224bb7..7cac82f543e 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -891,7 +891,16 @@ def islower(self) -> T_DataArray: Returns ------- islower : array of bool - Array of boolean values with the same shape as the original array. + Array of boolean values with the same shape as the original array indicating whether each + element of the string array is lowercase (True) or not (False). + + Example + ------- + >>> da = xr.DataArray(['temperature', 'HUMIDITY', 'pREciPiTaTioN'], dims='x') + >>> da + array(['temperature', 'HUMIDITY', 'pREciPiTaTioN'], dtype='>> da.str.islower() + array([ True, False, False]) """ return self._apply(func=lambda x: x.islower(), dtype=bool) From 6bcdd2d07491ed39c5ccc0882464dbce3153c5a4 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Fri, 24 Mar 2023 09:56:47 +0300 Subject: [PATCH 16/44] Add docstring example for DataArray.str.isnumeric --- xarray/core/accessor_str.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 7cac82f543e..33716e6a3f3 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -912,6 +912,14 @@ def isnumeric(self) -> T_DataArray: ------- isnumeric : array of bool Array of boolean values with the same shape as the original array. + + Example + ------- + >>> da = xr.DataArray(['123', '2.3', 'H2O', 'NaCl-', 'Mn'], dims='x') + >>> da + array(['123', '2.3', 'H2O', 'NaCl-', 'Mn'], dtype='>> da.str.isnumeric() + array([ True, False, False, False, False]) """ return self._apply(func=lambda x: x.isnumeric(), dtype=bool) From f6bc4c4e05ab9191ba9b3883e3878219d0e3f457 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Fri, 24 Mar 2023 09:58:51 +0300 Subject: [PATCH 17/44] Add docstring example for DataArray.str.isspace --- xarray/core/accessor_str.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 33716e6a3f3..1129b740a04 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -931,6 +931,14 @@ def isspace(self) -> T_DataArray: ------- isspace : array of bool Array of boolean values with the same shape as the original array. + + Example + ------- + >>> da = xr.DataArray(['', ' ', '\t', ' \n'], dims='x') + >>> da + array(['', ' ', '\t', ' \n'], dtype='>> da.str.isspace() + array([False, True, True, True]) """ return self._apply(func=lambda x: x.isspace(), dtype=bool) From ca75816656b785ca207c3976100ed605f0fbd7f4 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Fri, 24 Mar 2023 10:20:55 +0300 Subject: [PATCH 18/44] Add docstring example of DataArray.str.istitle --- xarray/core/accessor_str.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 1129b740a04..90d9d398ba4 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -950,6 +950,14 @@ def istitle(self) -> T_DataArray: ------- istitle : array of bool Array of boolean values with the same shape as the original array. + + Example + ------- + >>> da = xr.DataArray(['The Evolution Of Species', 'The Theory of relativity', 'the quantum mechanics of atoms'], dims='title') + >>> da + xr.DataArray(['The Evolution Of Species', 'The Theory of relativity', 'the quantum mechanics of atoms'], dims='title') + >>> da.str.istitle() + array([ True, False, False]) """ return self._apply(func=lambda x: x.istitle(), dtype=bool) From 68b3203fa601a169f8ecac8ccb1a5fcb91b969ce Mon Sep 17 00:00:00 2001 From: remigathoni Date: Fri, 24 Mar 2023 13:25:09 +0300 Subject: [PATCH 19/44] Add docstring example for DataArray.str.isupper --- xarray/core/accessor_str.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 90d9d398ba4..945910ac632 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -969,6 +969,14 @@ def isupper(self) -> T_DataArray: ------- isupper : array of bool Array of boolean values with the same shape as the original array. + + Example + ------- + >>> da = xr.DataArray(['TEMPERATURE', 'humidity', 'PreCIpiTAtioN'], dims='x') + >>> da + array(['TEMPERATURE', 'humidity', 'PreCIpiTAtioN'], dtype='>> da.str.isupper() + array([ True, False, False]) """ return self._apply(func=lambda x: x.isupper(), dtype=bool) From d5b2ff536a3c9b5775143828e15dfbf1eec4006d Mon Sep 17 00:00:00 2001 From: remigathoni Date: Fri, 24 Mar 2023 14:36:11 +0300 Subject: [PATCH 20/44] Add a docstring example for DataArray.str.count --- xarray/core/accessor_str.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 945910ac632..69cdae4d62d 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1012,6 +1012,29 @@ def count( Returns ------- counts : array of int + + Examples + -------- + >>> da = xr.DataArray(['jjklmn','opjjqrs','t-euuJJvwx'], dims='x') + >>> da + array(['jjklmn', 'opjjqrs', 't-euuJJvwx'], dtype='>> da.str.count("jj") + array([1, 1, 0]) + + Enable case-insensitive matching by setting case to false: + >>> import re + >>> da.str.count('jj', case=False) + array([1, 1, 1]) + + Using regex: + >>> da.str.count(r'jj') + array([1, 1, 0]) + + Using a list of strings (returns a count of matches for each element): + >>> da.str.count(['jj']) + array([2, 2, 0,]) """ pat = self._re_compile(pat=pat, flags=flags, case=case) From 5d9f5a217efbc0e2bfd1a5fb75553b9c09f1252f Mon Sep 17 00:00:00 2001 From: remigathoni Date: Fri, 24 Mar 2023 15:36:59 +0300 Subject: [PATCH 21/44] Add docstring example of DataArray.str.startswith --- xarray/core/accessor_str.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 69cdae4d62d..b27e5685881 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1059,6 +1059,14 @@ def startswith(self, pat: str | bytes | Any) -> T_DataArray: startswith : array of bool An array of booleans indicating whether the given pattern matches the start of each string element. + + Example + ------- + >>> da=xr.DataArray(['$100','£23', '100'], dims='x') + >>> da + array(['$100', '£23', '100'], dtype='>> da.str.startswith("$") + array([ True, False, False]) """ pat = self._stringify(pat) func = lambda x, y: x.startswith(y) From 988392e839a9a94350fe28bc94703d860fcb32ab Mon Sep 17 00:00:00 2001 From: remigathoni Date: Fri, 24 Mar 2023 15:39:43 +0300 Subject: [PATCH 22/44] Add docstring example of DataArray.str.endswith --- xarray/core/accessor_str.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index b27e5685881..783559d4e7d 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1090,6 +1090,14 @@ def endswith(self, pat: str | bytes | Any) -> T_DataArray: endswith : array of bool A Series of booleans indicating whether the given pattern matches the end of each string element. + + Example + ------- + >>> da=xr.DataArray(['10C', '10c''100F'], dims='x') + >>> da + array(['10C', '10c', '100F'], dtype='>> da.str.endswith("C") + array([ True, False, False]) """ pat = self._stringify(pat) func = lambda x, y: x.endswith(y) From 78ac9f7ece8d09ff0ee4bcb8e9dbf72e46dab831 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Fri, 24 Mar 2023 16:02:31 +0300 Subject: [PATCH 23/44] Use varied examples --- xarray/core/accessor_str.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 783559d4e7d..86380213d20 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -675,11 +675,11 @@ def capitalize(self) -> T_DataArray: Example ------- - >>> da = xr.DataArray(['temperature', 'pressure'], dims="item") + >>> da = xr.DataArray(['temperature', 'PRESSURE', 'PreCipiTation', 'daily rainfall'], dims="x") >>> da - array(['temperature', 'pressure'], dtype='>> da.str.capitalize() - array(['Temperature', 'Pressure'], dtype=' Date: Fri, 24 Mar 2023 13:09:12 +0000 Subject: [PATCH 24/44] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/core/accessor_str.py | 73 +++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 86380213d20..10de16fcb50 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -675,7 +675,9 @@ def capitalize(self) -> T_DataArray: Example ------- - >>> da = xr.DataArray(['temperature', 'PRESSURE', 'PreCipiTation', 'daily rainfall'], dims="x") + >>> da = xr.DataArray( + ... ["temperature", "PRESSURE", "PreCipiTation", "daily rainfall"], dims="x" + ... ) >>> da array(['temperature', 'PRESSURE', 'PreCipiTation', 'daily rainfall'], dtype='>> da.str.capitalize() @@ -693,7 +695,7 @@ def lower(self) -> T_DataArray: Example ------- - >>> da = xr.DataArray(['Temperature', 'PRESSURE'], dims="item") + >>> da = xr.DataArray(["Temperature", "PRESSURE"], dims="item") >>> da array(['Temperature', 'PRESSURE'], dtype='>> da.str.lower() @@ -711,7 +713,7 @@ def swapcase(self) -> T_DataArray: Example ------- - >>> da = xr.DataArray(['temperature', 'PRESSURE', 'HuMiDiTy'], dims="item") + >>> da = xr.DataArray(["temperature", "PRESSURE", "HuMiDiTy"], dims="item") >>> da array(['temperature', 'PRESSURE', 'HuMiDiTy'], dtype='>> da.str.swapcase() @@ -729,7 +731,7 @@ def title(self) -> T_DataArray: Example ------- - >>> da = xr.DataArray(['temperature', 'PRESSURE', 'HuMiDiTy'], dims="item") + >>> da = xr.DataArray(["temperature", "PRESSURE", "HuMiDiTy"], dims="item") >>> da array(['temperature', 'PRESSURE', 'HuMiDiTy'], dtype='>> da.str.title() @@ -747,7 +749,7 @@ def upper(self) -> T_DataArray: Example ------- - >>> da = xr.DataArray(['temperature', 'HuMiDiTy'], dims="item") + >>> da = xr.DataArray(["temperature", "HuMiDiTy"], dims="item") >>> da array(['temperature', 'HuMiDiTy'], dtype='>> da.str.upper() @@ -772,13 +774,13 @@ def casefold(self) -> T_DataArray: Examples -------- - >>> da = xr.DataArray(['TEMPERATURE', 'HuMiDiTy'], dims="item") + >>> da = xr.DataArray(["TEMPERATURE", "HuMiDiTy"], dims="item") >>> da array(['TEMPERATURE', 'HuMiDiTy'], dtype='>> da.str.casefold() array(['temperature', 'humidity'], dtype='>> da = xr.DataArray(['ß', 'İ'], dims='x') + >>> da = xr.DataArray(["ß", "İ"], dims="x") >>> da array(['ß', 'İ'], dtype='>> da.str.casefold() @@ -819,7 +821,7 @@ def isalnum(self) -> T_DataArray: Example ------- - >>> da = xr.DataArray(['H2O', 'NaCl-'], dims='x') + >>> da = xr.DataArray(["H2O", "NaCl-"], dims="x") >>> da array(['H2O', 'NaCl-'], dtype='>> da.str.isalnum() @@ -835,10 +837,10 @@ def isalpha(self) -> T_DataArray: ------- isalpha : array of bool Array of boolean values with the same shape as the original array. - + Example ------- - >>> da = xr.DataArray(['Mn' 'H2O', 'NaCl-'], dims='x') + >>> da = xr.DataArray(["Mn" "H2O", "NaCl-"], dims="x") >>> da array(['Mn', 'H2O', 'NaCl-'], dtype='>> da.str.isalpha() @@ -854,10 +856,10 @@ def isdecimal(self) -> T_DataArray: ------- isdecimal : array of bool Array of boolean values with the same shape as the original array. - + Example ------- - >>> da = xr.DataArray(['2.3', '123', '0'], dims='x') + >>> da = xr.DataArray(["2.3", "123", "0"], dims="x") >>> da array(['2.3', '123', '0'], dtype='>> da.str.isdecimal() @@ -873,10 +875,10 @@ def isdigit(self) -> T_DataArray: ------- isdigit : array of bool Array of boolean values with the same shape as the original array. - + Example ------- - >>> da = xr.DataArray(['123', '1.2', '0', 'CO2', 'NaCl'], dims='x') + >>> da = xr.DataArray(["123", "1.2", "0", "CO2", "NaCl"], dims="x") >>> da array(['123', '1.2', '0', 'CO2', 'NaCl'], dtype='>> da.str.isdigit() @@ -893,10 +895,10 @@ def islower(self) -> T_DataArray: islower : array of bool Array of boolean values with the same shape as the original array indicating whether each element of the string array is lowercase (True) or not (False). - + Example ------- - >>> da = xr.DataArray(['temperature', 'HUMIDITY', 'pREciPiTaTioN'], dims='x') + >>> da = xr.DataArray(["temperature", "HUMIDITY", "pREciPiTaTioN"], dims="x") >>> da array(['temperature', 'HUMIDITY', 'pREciPiTaTioN'], dtype='>> da.str.islower() @@ -912,10 +914,10 @@ def isnumeric(self) -> T_DataArray: ------- isnumeric : array of bool Array of boolean values with the same shape as the original array. - + Example ------- - >>> da = xr.DataArray(['123', '2.3', 'H2O', 'NaCl-', 'Mn'], dims='x') + >>> da = xr.DataArray(["123", "2.3", "H2O", "NaCl-", "Mn"], dims="x") >>> da array(['123', '2.3', 'H2O', 'NaCl-', 'Mn'], dtype='>> da.str.isnumeric() @@ -931,10 +933,10 @@ def isspace(self) -> T_DataArray: ------- isspace : array of bool Array of boolean values with the same shape as the original array. - + Example ------- - >>> da = xr.DataArray(['', ' ', '\t', ' \n'], dims='x') + >>> da = xr.DataArray(["", " ", "\t", " \n"], dims="x") >>> da array(['', ' ', '\t', ' \n'], dtype='>> da.str.isspace() @@ -950,10 +952,17 @@ def istitle(self) -> T_DataArray: ------- istitle : array of bool Array of boolean values with the same shape as the original array. - + Example ------- - >>> da = xr.DataArray(['The Evolution Of Species', 'The Theory of relativity', 'the quantum mechanics of atoms'], dims='title') + >>> da = xr.DataArray( + ... [ + ... "The Evolution Of Species", + ... "The Theory of relativity", + ... "the quantum mechanics of atoms", + ... ], + ... dims="title", + ... ) >>> da xr.DataArray(['The Evolution Of Species', 'The Theory of relativity', 'the quantum mechanics of atoms'], dims='title') >>> da.str.istitle() @@ -969,10 +978,10 @@ def isupper(self) -> T_DataArray: ------- isupper : array of bool Array of boolean values with the same shape as the original array. - + Example ------- - >>> da = xr.DataArray(['TEMPERATURE', 'humidity', 'PreCIpiTAtioN'], dims='x') + >>> da = xr.DataArray(["TEMPERATURE", "humidity", "PreCIpiTAtioN"], dims="x") >>> da array(['TEMPERATURE', 'humidity', 'PreCIpiTAtioN'], dtype='>> da.str.isupper() @@ -1015,7 +1024,7 @@ def count( Examples -------- - >>> da = xr.DataArray(['jjklmn','opjjqrs','t-euuJJvwx'], dims='x') + >>> da = xr.DataArray(["jjklmn", "opjjqrs", "t-euuJJvwx"], dims="x") >>> da array(['jjklmn', 'opjjqrs', 't-euuJJvwx'], dtype='>> import re - >>> da.str.count('jj', case=False) + >>> da.str.count("jj", case=False) array([1, 1, 1]) Using regex: - >>> da.str.count(r'jj') + >>> da.str.count(r"jj") array([1, 1, 0]) Using a list of strings (returns a count of matches for each element): - >>> da.str.count(['jj']) + >>> da.str.count(["jj"]) array([2, 2, 0,]) """ pat = self._re_compile(pat=pat, flags=flags, case=case) @@ -1059,10 +1068,10 @@ def startswith(self, pat: str | bytes | Any) -> T_DataArray: startswith : array of bool An array of booleans indicating whether the given pattern matches the start of each string element. - + Example ------- - >>> da=xr.DataArray(['$100','£23', '100'], dims='x') + >>> da = xr.DataArray(["$100", "£23", "100"], dims="x") >>> da array(['$100', '£23', '100'], dtype='>> da.str.startswith("$") @@ -1093,10 +1102,10 @@ def endswith(self, pat: str | bytes | Any) -> T_DataArray: Example ------- - >>> da=xr.DataArray(['10C', '10c''100F'], dims='x') + >>> da = xr.DataArray(["10C", "10c" "100F"], dims="x") >>> da array(['10C', '10c', '100F'], dtype='>> da.str.endswith("C") + >>> da.str.endswith("C") array([ True, False, False]) """ pat = self._stringify(pat) From 27d143adbc74ee264733fa3183ee56f8199c88f0 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Fri, 24 Mar 2023 16:54:09 +0300 Subject: [PATCH 25/44] Escape \n and \t Solves the incosistent whitespace error --- xarray/core/accessor_str.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 86380213d20..812d4319eb6 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -934,9 +934,9 @@ def isspace(self) -> T_DataArray: Example ------- - >>> da = xr.DataArray(['', ' ', '\t', ' \n'], dims='x') + >>> da = xr.DataArray(['', ' ', '\\t', '\\n'], dims='x') >>> da - array(['', ' ', '\t', ' \n'], dtype='>> da.str.isspace() array([False, True, True, True]) """ From 437362289fa247502b555f1eb80b6d2b84add757 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 24 Mar 2023 14:07:49 +0000 Subject: [PATCH 26/44] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/core/accessor_str.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index d4869fac5c8..0a4a2a91a8a 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -936,7 +936,7 @@ def isspace(self) -> T_DataArray: Example ------- - >>> da = xr.DataArray(['', ' ', '\\t', '\\n'], dims='x') + >>> da = xr.DataArray(["", " ", "\\t", "\\n"], dims="x") >>> da array(['', ' ', '\\t', '\\n'], dtype='>> da.str.isspace() From 355171a8a16664402f3778cfe1dab07a26a283f7 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Fri, 24 Mar 2023 20:07:56 +0300 Subject: [PATCH 27/44] Fixes failing doctests --- xarray/core/accessor_str.py | 183 ++++++++++++++++++++++++++++-------- 1 file changed, 145 insertions(+), 38 deletions(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index d4869fac5c8..44a967b6bb1 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -679,9 +679,16 @@ def capitalize(self) -> T_DataArray: ... ["temperature", "PRESSURE", "PreCipiTation", "daily rainfall"], dims="x" ... ) >>> da - array(['temperature', 'PRESSURE', 'PreCipiTation', 'daily rainfall'], dtype='>> da.str.capitalize() - array(['Temperature', 'Pressure', 'Precipitation', 'Daily rainfall'], dtype=' + array(['temperature', 'PRESSURE', 'PreCipiTation', 'daily rainfall'], + dtype='>> capitalized = da.str.capitalize() + >>> capitalized + + array(['Temperature', 'Pressure', 'Precipitation', 'Daily rainfall'], + dtype=' T_DataArray: Example ------- - >>> da = xr.DataArray(["Temperature", "PRESSURE"], dims="item") + >>> da = xr.DataArray(["Temperature", "PRESSURE"], dims="x") >>> da + array(['Temperature', 'PRESSURE'], dtype='>> da.str.lower() + Dimensions without coordinates: x + >>> lowerd = da.str.lower() + >>> lowerd + array(['temperature', 'pressure'], dtype=' T_DataArray: ------- swapcased : same type as values - Example - ------- - >>> da = xr.DataArray(["temperature", "PRESSURE", "HuMiDiTy"], dims="item") + Examples + -------- + >>> import xarray as xr + >>> da = xr.DataArray(["temperature", "PRESSURE", "HuMiDiTy"], dims="x") >>> da + array(['temperature', 'PRESSURE', 'HuMiDiTy'], dtype='>> da.str.swapcase() + Dimensions without coordinates: x + >>> swapcased = da.str.swapcase() + >>> swapcased + array(['TEMPERATURE', 'pressure', 'hUmIdItY'], dtype=' T_DataArray: Example ------- - >>> da = xr.DataArray(["temperature", "PRESSURE", "HuMiDiTy"], dims="item") + >>> da = xr.DataArray(["temperature", "PRESSURE", "HuMiDiTy"], dims="x") >>> da + array(['temperature', 'PRESSURE', 'HuMiDiTy'], dtype='>> da.str.title() + Dimensions without coordinates: x + >>> titled = da.str.title() + >>> titled + array(['Temperature', 'Pressure', 'Humidity'], dtype=' T_DataArray: Example ------- - >>> da = xr.DataArray(["temperature", "HuMiDiTy"], dims="item") + >>> da = xr.DataArray(["temperature", "HuMiDiTy"], dims="x") >>> da + array(['temperature', 'HuMiDiTy'], dtype='>> da.str.upper() + Dimensions without coordinates: x + >>> uppered = da.str.upper() + >>> uppered + array(['TEMPERATURE', 'HUMIDITY'], dtype=' T_DataArray: Examples -------- - >>> da = xr.DataArray(["TEMPERATURE", "HuMiDiTy"], dims="item") + >>> da = xr.DataArray(["TEMPERATURE", "HuMiDiTy"], dims="x") >>> da + array(['TEMPERATURE', 'HuMiDiTy'], dtype='>> da.str.casefold() + Dimensions without coordinates: x + >>> casefolded = da.str.casefold() + >>> casefolded + array(['temperature', 'humidity'], dtype='>> da = xr.DataArray(["ß", "İ"], dims="x") >>> da + array(['ß', 'İ'], dtype='>> da.str.casefold() + Dimensions without coordinates: x + >>> casefolded = da.str.casefold() + >>> casefolded + array(['ss', 'i̇'], dtype=' T_DataArray: ------- >>> da = xr.DataArray(["H2O", "NaCl-"], dims="x") >>> da + array(['H2O', 'NaCl-'], dtype='>> da.str.isalnum() + Dimensions without coordinates: x + >>> isalnum = da.str.isalnum() + >>> isalnum + array([ True, False]) + Dimensions without coordinates: x """ return self._apply(func=lambda x: x.isalnum(), dtype=bool) @@ -840,11 +883,16 @@ def isalpha(self) -> T_DataArray: Example ------- - >>> da = xr.DataArray(["Mn" "H2O", "NaCl-"], dims="x") + >>> da = xr.DataArray(["Mn", "H2O", "NaCl-"], dims="x") >>> da + array(['Mn', 'H2O', 'NaCl-'], dtype='>> da.str.isalpha() + Dimensions without coordinates: x + >>> isalpha = da.str.isalpha() + >>> isalpha + array([ True, False, False]) + Dimensions without coordinates: x """ return self._apply(func=lambda x: x.isalpha(), dtype=bool) @@ -861,9 +909,14 @@ def isdecimal(self) -> T_DataArray: ------- >>> da = xr.DataArray(["2.3", "123", "0"], dims="x") >>> da + array(['2.3', '123', '0'], dtype='>> da.str.isdecimal() + Dimensions without coordinates: x + >>> isdecimal = da.str.isdecimal() + >>> isdecimal + array([False, True, True]) + Dimensions without coordinates: x """ return self._apply(func=lambda x: x.isdecimal(), dtype=bool) @@ -880,9 +933,14 @@ def isdigit(self) -> T_DataArray: ------- >>> da = xr.DataArray(["123", "1.2", "0", "CO2", "NaCl"], dims="x") >>> da + array(['123', '1.2', '0', 'CO2', 'NaCl'], dtype='>> da.str.isdigit() + Dimensions without coordinates: x + >>> isdigit = da.str.isdigit() + >>> isdigit + array([ True, False, True, False, False]) + Dimensions without coordinates: x """ return self._apply(func=lambda x: x.isdigit(), dtype=bool) @@ -900,9 +958,14 @@ def islower(self) -> T_DataArray: ------- >>> da = xr.DataArray(["temperature", "HUMIDITY", "pREciPiTaTioN"], dims="x") >>> da + array(['temperature', 'HUMIDITY', 'pREciPiTaTioN'], dtype='>> da.str.islower() + Dimensions without coordinates: x + >>> islower = da.str.islower() + >>> islower + array([ True, False, False]) + Dimensions without coordinates: x """ return self._apply(func=lambda x: x.islower(), dtype=bool) @@ -919,9 +982,14 @@ def isnumeric(self) -> T_DataArray: ------- >>> da = xr.DataArray(["123", "2.3", "H2O", "NaCl-", "Mn"], dims="x") >>> da + array(['123', '2.3', 'H2O', 'NaCl-', 'Mn'], dtype='>> da.str.isnumeric() + Dimensions without coordinates: x + >>> isnumeric = da.str.isnumeric() + >>> isnumeric + array([ True, False, False, False, False]) + Dimensions without coordinates: x """ return self._apply(func=lambda x: x.isnumeric(), dtype=bool) @@ -938,9 +1006,14 @@ def isspace(self) -> T_DataArray: ------- >>> da = xr.DataArray(['', ' ', '\\t', '\\n'], dims='x') >>> da - array(['', ' ', '\\t', '\\n'], dtype='>> da.str.isspace() + + array(['', ' ', '\\t', '\\n'], dtype='>> isspace = da.str.isspace() + >>> isspace + array([False, True, True, True]) + Dimensions without coordinates: x """ return self._apply(func=lambda x: x.isspace(), dtype=bool) @@ -964,9 +1037,15 @@ def istitle(self) -> T_DataArray: ... dims="title", ... ) >>> da - xr.DataArray(['The Evolution Of Species', 'The Theory of relativity', 'the quantum mechanics of atoms'], dims='title') - >>> da.str.istitle() + + array(['The Evolution Of Species', 'The Theory of relativity', + 'the quantum mechanics of atoms'], dtype='>> istitle = da.str.istitle() + >>> istitle + array([ True, False, False]) + Dimensions without coordinates: title """ return self._apply(func=lambda x: x.istitle(), dtype=bool) @@ -982,10 +1061,15 @@ def isupper(self) -> T_DataArray: Example ------- >>> da = xr.DataArray(["TEMPERATURE", "humidity", "PreCIpiTAtioN"], dims="x") - >>> da + >>> da + array(['TEMPERATURE', 'humidity', 'PreCIpiTAtioN'], dtype='>> da.str.isupper() + Dimensions without coordinates: x + >>> isupper = da.str.isupper() + >>> isupper + array([ True, False, False]) + Dimensions without coordinates: x """ return self._apply(func=lambda x: x.isupper(), dtype=bool) @@ -1026,24 +1110,37 @@ def count( -------- >>> da = xr.DataArray(["jjklmn", "opjjqrs", "t-euuJJvwx"], dims="x") >>> da + array(['jjklmn', 'opjjqrs', 't-euuJJvwx'], dtype='>> da.str.count("jj") + array([1, 1, 0]) + Dimensions without coordinates: x Enable case-insensitive matching by setting case to false: >>> import re - >>> da.str.count("jj", case=False) + >>> counts = da.str.count("jj", case=False) + >>> counts + array([1, 1, 1]) + Dimensions without coordinates: x Using regex: - >>> da.str.count(r"jj") + >>> counts = da.str.count(r"jj") + >>> counts + array([1, 1, 0]) - + Dimensions without coordinates: x + Using a list of strings (returns a count of matches for each element): - >>> da.str.count(["jj"]) - array([2, 2, 0,]) + >>> counts = da.str.count(["jj"]) + >>> counts + + array([2, 2, 0]) + Dimensions without coordinates: x """ pat = self._re_compile(pat=pat, flags=flags, case=case) @@ -1073,9 +1170,14 @@ def startswith(self, pat: str | bytes | Any) -> T_DataArray: ------- >>> da = xr.DataArray(["$100", "£23", "100"], dims="x") >>> da + array(['$100', '£23', '100'], dtype='>> da.str.startswith("$") - array([ True, False, False]) + Dimensions without coordinates: x + >>> startswith = da.str.startswith("$") + >>> startswith + + array([ True, False, False]) + Dimensions without coordinates: x """ pat = self._stringify(pat) func = lambda x, y: x.startswith(y) @@ -1102,11 +1204,16 @@ def endswith(self, pat: str | bytes | Any) -> T_DataArray: Example ------- - >>> da = xr.DataArray(["10C", "10c" "100F"], dims="x") + >>> da = xr.DataArray(["10C", "10c", "100F"], dims="x") >>> da + array(['10C', '10c', '100F'], dtype='>> da.str.endswith("C") + Dimensions without coordinates: x + >>> endswith = da.str.endswith("C") + >>> endswith + array([ True, False, False]) + Dimensions without coordinates: x """ pat = self._stringify(pat) func = lambda x, y: x.endswith(y) From 564fe5674fb34b9f1196b6671e37b923b22ae173 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 24 Mar 2023 17:13:38 +0000 Subject: [PATCH 28/44] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/core/accessor_str.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 184752ca7de..34108215c5c 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1061,7 +1061,7 @@ def isupper(self) -> T_DataArray: Example ------- >>> da = xr.DataArray(["TEMPERATURE", "humidity", "PreCIpiTAtioN"], dims="x") - >>> da + >>> da array(['TEMPERATURE', 'humidity', 'PreCIpiTAtioN'], dtype=' array([1, 1, 0]) Dimensions without coordinates: x - + Using a list of strings (returns a count of matches for each element): >>> counts = da.str.count(["jj"]) >>> counts From d358bf962dd46e9b9666dc09912099ff0e6f524e Mon Sep 17 00:00:00 2001 From: remigathoni Date: Fri, 24 Mar 2023 20:42:08 +0300 Subject: [PATCH 29/44] Replace "Example" with "Examples" To follow the Numpy docstrings format. --- xarray/core/accessor_str.py | 60 ++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 34108215c5c..a2c30f9b497 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -673,8 +673,8 @@ def capitalize(self) -> T_DataArray: ------- capitalized : same type as values - Example - ------- + Examples + -------- >>> da = xr.DataArray( ... ["temperature", "PRESSURE", "PreCipiTation", "daily rainfall"], dims="x" ... ) @@ -700,8 +700,8 @@ def lower(self) -> T_DataArray: ------- lowerd : same type as values - Example - ------- + Examples + -------- >>> da = xr.DataArray(["Temperature", "PRESSURE"], dims="x") >>> da @@ -747,8 +747,8 @@ def title(self) -> T_DataArray: ------- titled : same type as values - Example - ------- + Examples + -------- >>> da = xr.DataArray(["temperature", "PRESSURE", "HuMiDiTy"], dims="x") >>> da @@ -770,8 +770,8 @@ def upper(self) -> T_DataArray: ------- uppered : same type as values - Example - ------- + Examples + -------- >>> da = xr.DataArray(["temperature", "HuMiDiTy"], dims="x") >>> da @@ -857,8 +857,8 @@ def isalnum(self) -> T_DataArray: isalnum : array of bool Array of boolean values with the same shape as the original array. - Example - ------- + Examples + -------- >>> da = xr.DataArray(["H2O", "NaCl-"], dims="x") >>> da @@ -881,8 +881,8 @@ def isalpha(self) -> T_DataArray: isalpha : array of bool Array of boolean values with the same shape as the original array. - Example - ------- + Examples + -------- >>> da = xr.DataArray(["Mn", "H2O", "NaCl-"], dims="x") >>> da @@ -905,8 +905,8 @@ def isdecimal(self) -> T_DataArray: isdecimal : array of bool Array of boolean values with the same shape as the original array. - Example - ------- + Examples + -------- >>> da = xr.DataArray(["2.3", "123", "0"], dims="x") >>> da @@ -929,8 +929,8 @@ def isdigit(self) -> T_DataArray: isdigit : array of bool Array of boolean values with the same shape as the original array. - Example - ------- + Examples + -------- >>> da = xr.DataArray(["123", "1.2", "0", "CO2", "NaCl"], dims="x") >>> da @@ -954,8 +954,8 @@ def islower(self) -> T_DataArray: Array of boolean values with the same shape as the original array indicating whether each element of the string array is lowercase (True) or not (False). - Example - ------- + Examples + -------- >>> da = xr.DataArray(["temperature", "HUMIDITY", "pREciPiTaTioN"], dims="x") >>> da @@ -978,8 +978,8 @@ def isnumeric(self) -> T_DataArray: isnumeric : array of bool Array of boolean values with the same shape as the original array. - Example - ------- + Examples + -------- >>> da = xr.DataArray(["123", "2.3", "H2O", "NaCl-", "Mn"], dims="x") >>> da @@ -1002,8 +1002,8 @@ def isspace(self) -> T_DataArray: isspace : array of bool Array of boolean values with the same shape as the original array. - Example - ------- + Examples + -------- >>> da = xr.DataArray(["", " ", "\\t", "\\n"], dims="x") >>> da @@ -1026,8 +1026,8 @@ def istitle(self) -> T_DataArray: istitle : array of bool Array of boolean values with the same shape as the original array. - Example - ------- + Examples + -------- >>> da = xr.DataArray( ... [ ... "The Evolution Of Species", @@ -1058,8 +1058,8 @@ def isupper(self) -> T_DataArray: isupper : array of bool Array of boolean values with the same shape as the original array. - Example - ------- + Examples + -------- >>> da = xr.DataArray(["TEMPERATURE", "humidity", "PreCIpiTAtioN"], dims="x") >>> da @@ -1166,8 +1166,8 @@ def startswith(self, pat: str | bytes | Any) -> T_DataArray: An array of booleans indicating whether the given pattern matches the start of each string element. - Example - ------- + Examples + -------- >>> da = xr.DataArray(["$100", "£23", "100"], dims="x") >>> da @@ -1202,8 +1202,8 @@ def endswith(self, pat: str | bytes | Any) -> T_DataArray: A Series of booleans indicating whether the given pattern matches the end of each string element. - Example - ------- + Examples + -------- >>> da = xr.DataArray(["10C", "10c", "100F"], dims="x") >>> da From f6fe0d5bc22aa0981b70b2369113f3ab42235903 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Mon, 27 Mar 2023 15:36:28 +0300 Subject: [PATCH 30/44] Delete unnecessary import --- xarray/core/accessor_str.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index a2c30f9b497..385f6154c43 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1121,7 +1121,6 @@ def count( Dimensions without coordinates: x Enable case-insensitive matching by setting case to false: - >>> import re >>> counts = da.str.count("jj", case=False) >>> counts From f5641c2f61559d1122219b691d746d02ff20f008 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Tue, 28 Mar 2023 01:20:58 +0300 Subject: [PATCH 31/44] Pass a regex to the count function --- xarray/core/accessor_str.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 385f6154c43..630d7feaf53 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1128,7 +1128,8 @@ def count( Dimensions without coordinates: x Using regex: - >>> counts = da.str.count(r"jj") + >>> pat = 'jj\\w+' + >>> counts = da.str.count(pat) >>> counts array([1, 1, 0]) From 6e1c9d9bc0d830cb2f2485411e0bd55a9c643c8d Mon Sep 17 00:00:00 2001 From: remigathoni Date: Tue, 28 Mar 2023 01:23:46 +0300 Subject: [PATCH 32/44] Pass an array of strings to the count function This example demonstrates how the pattern is broadcasted. --- xarray/core/accessor_str.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 630d7feaf53..83a3d064f19 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1135,12 +1135,15 @@ def count( array([1, 1, 0]) Dimensions without coordinates: x - Using a list of strings (returns a count of matches for each element): - >>> counts = da.str.count(["jj"]) + Using an array of strings (the pattern will be broadcast against the array): + >>> pat= xr.DataArray(["jj", "JJ"], dims="y") + >>> counts = da.str.count(pat) >>> counts - - array([2, 2, 0]) - Dimensions without coordinates: x + + array([[1, 0], + [1, 0], + [0, 1]]) + Dimensions without coordinates: x, y """ pat = self._re_compile(pat=pat, flags=flags, case=case) From ec8a1066910ebe3d68549737bf65fa07d2b6395b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Mar 2023 22:24:48 +0000 Subject: [PATCH 33/44] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/core/accessor_str.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 83a3d064f19..41da851e5fa 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1128,7 +1128,7 @@ def count( Dimensions without coordinates: x Using regex: - >>> pat = 'jj\\w+' + >>> pat = "jj\\w+" >>> counts = da.str.count(pat) >>> counts @@ -1136,7 +1136,7 @@ def count( Dimensions without coordinates: x Using an array of strings (the pattern will be broadcast against the array): - >>> pat= xr.DataArray(["jj", "JJ"], dims="y") + >>> pat = xr.DataArray(["jj", "JJ"], dims="y") >>> counts = da.str.count(pat) >>> counts From 306f09a30ea2ff467140cae25cbc938b37051e60 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Tue, 28 Mar 2023 19:06:56 +0300 Subject: [PATCH 34/44] Add docstrings examples for DataArray.str.pad --- xarray/core/accessor_str.py | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 83a3d064f19..08aa3df8aa9 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1250,6 +1250,49 @@ def pad( ------- filled : same type as values Array with a minimum number of char in each element. + + Examples + -------- + Pad strings in the array with a single string on the left side. + + Define the string in the array. + >>> da=xr.DataArray(['PAR184', 'TKO65', 'NBO9139', 'NZ39'], dims='x') + + Pad the strings + >>> filled = da.str.pad(8, side='left', fillchar='0') + >>> filled + + array(['00PAR184', '000TKO65', '0NBO9139', '0000NZ39'], dtype='>> filled = da.str.pad(8, side='right', fillchar='0') + >>> filled + + array(['PAR18400', 'TKO65000', 'NBO91390', 'NZ390000'], dtype='>> filled = da.str.pad(8, side='both', fillchar='0') + >>> filled + + array(['0PAR1840', '0TKO6500', 'NBO91390', '00NZ3900'], dtype='>> width = xr.DataArray([8,10], dims='y') + >>> filled = da.str.pad(width, side='left', fillchar='0') + >>> filled + + array([['00PAR184', '0000PAR184'], + ['000TKO65', '00000TKO65'], + ['0NBO9139', '000NBO9139'], + ['0000NZ39', '000000NZ39']], dtype='>> fillchar = xr.DataArray(['0','-'], dims='y') + >>> filled = da.str.pad(8, side='left', fillchar=fillchar) """ if side == "left": func = self.rjust From b027cc7575e07423c2211d7c0756d471fa29485e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 28 Mar 2023 16:09:20 +0000 Subject: [PATCH 35/44] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/core/accessor_str.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 5dc7d23adc3..59a2fef4924 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1254,34 +1254,34 @@ def pad( Examples -------- Pad strings in the array with a single string on the left side. - + Define the string in the array. - >>> da=xr.DataArray(['PAR184', 'TKO65', 'NBO9139', 'NZ39'], dims='x') - + >>> da = xr.DataArray(["PAR184", "TKO65", "NBO9139", "NZ39"], dims="x") + Pad the strings - >>> filled = da.str.pad(8, side='left', fillchar='0') + >>> filled = da.str.pad(8, side="left", fillchar="0") >>> filled array(['00PAR184', '000TKO65', '0NBO9139', '0000NZ39'], dtype='>> filled = da.str.pad(8, side='right', fillchar='0') - >>> filled + >>> filled = da.str.pad(8, side="right", fillchar="0") + >>> filled array(['PAR18400', 'TKO65000', 'NBO91390', 'NZ390000'], dtype='>> filled = da.str.pad(8, side='both', fillchar='0') - >>> filled + >>> filled = da.str.pad(8, side="both", fillchar="0") + >>> filled array(['0PAR1840', '0TKO6500', 'NBO91390', '00NZ3900'], dtype='>> width = xr.DataArray([8,10], dims='y') - >>> filled = da.str.pad(width, side='left', fillchar='0') + >>> width = xr.DataArray([8, 10], dims="y") + >>> filled = da.str.pad(width, side="left", fillchar="0") >>> filled array([['00PAR184', '0000PAR184'], @@ -1291,8 +1291,8 @@ def pad( Dimensions without coordinates: x, y Using an array-like value for fillchar - >>> fillchar = xr.DataArray(['0','-'], dims='y') - >>> filled = da.str.pad(8, side='left', fillchar=fillchar) + >>> fillchar = xr.DataArray(["0", "-"], dims="y") + >>> filled = da.str.pad(8, side="left", fillchar=fillchar) """ if side == "left": func = self.rjust From 95d34312be95026d6c91a0133fd4b78791565952 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Thu, 30 Mar 2023 14:18:25 +0300 Subject: [PATCH 36/44] Fix invalid escape sequence warning --- xarray/core/accessor_str.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 5dc7d23adc3..bac064a0e07 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1108,10 +1108,10 @@ def count( Examples -------- - >>> da = xr.DataArray(["jjklmn", "opjjqrs", "t-euuJJvwx"], dims="x") + >>> da = xr.DataArray(["jjklmn", "opjjqrs", "t-JJ99vwx"], dims="x") >>> da - array(['jjklmn', 'opjjqrs', 't-euuJJvwx'], dtype='>> pat = "jj\\w+" + >>> pat = r'JJ\\d{2}[a-z]{3}' >>> counts = da.str.count(pat) >>> counts - array([1, 1, 0]) + array([0, 0, 1]) Dimensions without coordinates: x Using an array of strings (the pattern will be broadcast against the array): From 9b3f0b8c2b25101be2e6d6d3e37f3ebb43379702 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 Mar 2023 11:21:38 +0000 Subject: [PATCH 37/44] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/core/accessor_str.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index af00c1de5c1..59fdc1dc65e 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1128,7 +1128,7 @@ def count( Dimensions without coordinates: x Using regex: - >>> pat = r'JJ\\d{2}[a-z]{3}' + >>> pat = r"JJ\\d{2}[a-z]{3}" >>> counts = da.str.count(pat) >>> counts From c57ffc3bf3f82286eb4be47e068f598e822e54fa Mon Sep 17 00:00:00 2001 From: remigathoni Date: Thu, 30 Mar 2023 14:38:50 +0300 Subject: [PATCH 38/44] Fix regex --- xarray/core/accessor_str.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index af00c1de5c1..073d700d8ad 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1128,7 +1128,7 @@ def count( Dimensions without coordinates: x Using regex: - >>> pat = r'JJ\\d{2}[a-z]{3}' + >>> pat = 'JJ[0-9]{2}[a-z]{3}' >>> counts = da.str.count(pat) >>> counts From 856f3e85f39c03700b33cdd5bde8d8e17f216273 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 Mar 2023 11:51:56 +0000 Subject: [PATCH 39/44] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/core/accessor_str.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 073d700d8ad..2935be5f4cb 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1128,7 +1128,7 @@ def count( Dimensions without coordinates: x Using regex: - >>> pat = 'JJ[0-9]{2}[a-z]{3}' + >>> pat = "JJ[0-9]{2}[a-z]{3}" >>> counts = da.str.count(pat) >>> counts From a989e81a0d8c6f8701079ff002e57d504a240720 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Thu, 30 Mar 2023 15:02:56 +0300 Subject: [PATCH 40/44] Add data array and filled value --- xarray/core/accessor_str.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 2935be5f4cb..b60ce8d93a0 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1257,6 +1257,10 @@ def pad( Define the string in the array. >>> da = xr.DataArray(["PAR184", "TKO65", "NBO9139", "NZ39"], dims="x") + >>> da + + array(['PAR184', 'TKO65', 'NBO9139', 'NZ39'], dtype='>> filled = da.str.pad(8, side="left", fillchar="0") @@ -1293,6 +1297,13 @@ def pad( Using an array-like value for fillchar >>> fillchar = xr.DataArray(["0", "-"], dims="y") >>> filled = da.str.pad(8, side="left", fillchar=fillchar) + >>> filled + + array([['00PAR184', '--PAR184'], + ['000TKO65', '---TKO65'], + ['0NBO9139', '-NBO9139'], + ['0000NZ39', '----NZ39']], dtype=' Date: Thu, 30 Mar 2023 15:07:08 +0300 Subject: [PATCH 41/44] Correct spelling mistake --- xarray/core/accessor_str.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index b60ce8d93a0..302643e2373 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -698,7 +698,7 @@ def lower(self) -> T_DataArray: Returns ------- - lowerd : same type as values + lowered : same type as values Examples -------- @@ -707,8 +707,8 @@ def lower(self) -> T_DataArray: array(['Temperature', 'PRESSURE'], dtype='>> lowerd = da.str.lower() - >>> lowerd + >>> lowered = da.str.lower() + >>> lowered array(['temperature', 'pressure'], dtype=' Date: Thu, 30 Mar 2023 15:15:15 +0300 Subject: [PATCH 42/44] Modify wording to make it easier to understand --- xarray/core/accessor_str.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 302643e2373..baddec0a268 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -951,8 +951,8 @@ def islower(self) -> T_DataArray: Returns ------- islower : array of bool - Array of boolean values with the same shape as the original array indicating whether each - element of the string array is lowercase (True) or not (False). + Array of boolean values with the same shape as the original array indicating whether all characters of each + element of the string array are lowercase (True) or not (False). Examples -------- From 397f668894f1f1dc090a557db0a4166c5b07daf0 Mon Sep 17 00:00:00 2001 From: remigathoni Date: Mon, 17 Apr 2023 15:08:39 +0300 Subject: [PATCH 43/44] Fix indent errors --- xarray/core/accessor_str.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index baddec0a268..819f2d676c6 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1136,6 +1136,7 @@ def count( Dimensions without coordinates: x Using an array of strings (the pattern will be broadcast against the array): + >>> pat = xr.DataArray(["jj", "JJ"], dims="y") >>> counts = da.str.count(pat) >>> counts @@ -1284,6 +1285,7 @@ def pad( Dimensions without coordinates: x Using an array-like width + >>> width = xr.DataArray([8, 10], dims="y") >>> filled = da.str.pad(width, side="left", fillchar="0") >>> filled @@ -1295,6 +1297,7 @@ def pad( Dimensions without coordinates: x, y Using an array-like value for fillchar + >>> fillchar = xr.DataArray(["0", "-"], dims="y") >>> filled = da.str.pad(8, side="left", fillchar=fillchar) >>> filled From 384291585912ca195907f8506260f8f5cb80eb33 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Tue, 18 Apr 2023 16:20:00 -0600 Subject: [PATCH 44/44] Add whats-new, fix docs --- doc/whats-new.rst | 4 +++- xarray/core/accessor_str.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 1f3202370b4..131faf480fa 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -39,7 +39,9 @@ Bug fixes Documentation ~~~~~~~~~~~~~ - +- Added examples to docstrings for :py:meth:`xarray.core.accessor_str.StringAccessor` methods. + (:pull:`7669`) . + By `Mary Gathoni `_. Internal Changes ~~~~~~~~~~~~~~~~ diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 819f2d676c6..c6c4af87d1c 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1257,6 +1257,7 @@ def pad( Pad strings in the array with a single string on the left side. Define the string in the array. + >>> da = xr.DataArray(["PAR184", "TKO65", "NBO9139", "NZ39"], dims="x") >>> da @@ -1264,6 +1265,7 @@ def pad( Dimensions without coordinates: x Pad the strings + >>> filled = da.str.pad(8, side="left", fillchar="0") >>> filled @@ -1271,6 +1273,7 @@ def pad( Dimensions without coordinates: x Pad strings on the right side + >>> filled = da.str.pad(8, side="right", fillchar="0") >>> filled @@ -1278,6 +1281,7 @@ def pad( Dimensions without coordinates: x Pad strings on both sides + >>> filled = da.str.pad(8, side="both", fillchar="0") >>> filled