Skip to content
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

[WIP] Custom fill value for reindex, align, and merge operations #2920

Merged
merged 8 commits into from
May 5, 2019

Conversation

zdgriffith
Copy link
Contributor

@zdgriffith zdgriffith commented Apr 25, 2019

This PR adds an optional fill_value parameter for the following functions/methods:

xarray.core.alignment.align()
xarray.core.alignment.deep_align()

xarray.core.dataset.reindex()
xarray.core.dataset.reindex_like()
xarray.core.dataset.merge()

xarray.core.dataarray.DataArray.reindex()
xarray.core.dataarray.DataArray.reindex_like()

xarray.core.merge.merge_coords()
xarray.core.merge.merge_core()
xarray.core.merge.merge()
xarray.core.merge.dataset_merge_method()

The value given to fill_value is used to fill missing values in the new object after the operation. By default fill_value is NaN.

@pep8speaks
Copy link

pep8speaks commented Apr 25, 2019

Hello @zdgriffith! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-05-02 21:54:47 UTC

Copy link
Member

@shoyer shoyer left a comment

Choose a reason for hiding this comment

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

@zdgriffith this is fantastic, thank you!

I think the only thing that is missing is a brief release announcement in whats-new.rst

"""align(*objects, join='inner', copy=True, indexes=None,
exclude=frozenset())
"""align(*objects, join='inner', copy=True, fill_value=dtypes.NA,
indexes=None, exclude=frozenset())
Copy link
Member

@shoyer shoyer Apr 26, 2019

Choose a reason for hiding this comment

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

One small additional clean-up you could optionally do here: since we no longer support Python 2, these function signature could be moved from the docstring onto the function itself, e.g.,

def align(*objects, join='inner', copy=True, fill_value=dtypes.NA,
             indexes=None, exclude=frozenset())"

This would let you drop the calls to kwargs.pop() below, and would be a small win for efficiency/clean code.

@zdgriffith
Copy link
Contributor Author

Thanks for the review @shoyer! Would edits to the docs be in-scope for this PR? For example where fill values are mentioned in http://xarray.pydata.org/en/latest/indexing.html#align-and-reindex.

@shoyer
Copy link
Member

shoyer commented May 2, 2019

Would edits to the docs be in-scope for this PR?

Up to you. Would be happy to include any edits you think are appropriate but they aren't required. The API docs are the canonical reference for various function options but if you think there are good places to mention this option in the narrative docs that would also be welcome.

@dcherian
Copy link
Contributor

dcherian commented May 2, 2019

+1 for a line in the docs, I don't think an example is needed

@shoyer shoyer merged commit 5aaa654 into pydata:master May 5, 2019
@shoyer
Copy link
Member

shoyer commented May 5, 2019

thanks @zdgriffith!

@zdgriffith zdgriffith deleted the custom-fill-value branch May 5, 2019 20:31
dcherian added a commit to dcherian/xarray that referenced this pull request May 6, 2019
* upstream/master:
  [WIP] Custom fill value for reindex, align, and merge operations (pydata#2920)
  Attempt to fix py35 build on Travis (pydata#2925)
  List formatting in docs (pydata#2939)
  DOC: Avoid downloading .tif file (pydata#2919)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom fill value for align, reindex and reindex_like
4 participants