Skip to content

interp() now accepts date strings as desired co-ordinate locations #2325

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 6 commits into from
Jul 29, 2018

Conversation

dcherian
Copy link
Contributor

  • Closes interp over time coordinate #2284
  • Tests added (for all bug fixes or enhancements)
  • Tests passed (for all non-documentation changes)
  • Fully documented, including whats-new.rst for all changes and api.rst for new API (remove if this change should not be visible to users, e.g., if it is an internal clean-up, or if this is part of a larger project that will be documented later)
da = xr.DataArray([1, 5],
                  dims=['time'],
                  coords={'time': [np.datetime64('2014-05-06'),
                                   np.datetime64('2014-05-10')]})

da.interp(time='2014-05-07')
<xarray.DataArray ()>
array(2.)
Coordinates:
    time     datetime64[ns] 2014-05-07

@@ -1328,6 +1330,12 @@ def _validate_indexers(self, indexers):
raise TypeError('cannot use a Dataset as an indexer')
else:
v = np.asarray(v)

if (v.dtype.kind == 'U'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

only the first half is really required (the tests all pass), but I added the second bit to be safe.

@fujiisoup
Copy link
Member

fujiisoup commented Jul 28, 2018

Thanks, @dcherian .

It looks already great, but can you add a bit more test cases to keep it working with the future modification?
It would be nicer if we can check

  • If xnew is a single datetime unicode such as '2014-05-07`
  • If xnew is pd.datetime

I think they will be passing with the current PR though.

@fujiisoup
Copy link
Member

Can you merge master? It will solve some failures in CI.
I also noticed tests in Python=2.7 are failing.

dcherian added 3 commits July 28, 2018 14:05
Copy link
Member

@fujiisoup fujiisoup left a comment

Choose a reason for hiding this comment

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

Thanks a lot. I think issue #2327 is solved and we can safely remove the corresponding line.

Other part looks nice to me:)

(np.array([np.datetime64('2000-01-01T12:00'),
np.datetime64('2000-01-02T12:00')]), [0.5, 1.5]),
(['2000-01-01T12:00', '2000-01-02T12:00'], [0.5, 1.5]),
(['2000-01-01T12:00'], 0.5) # needs to be list, see #2327
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove the comment and add a test with a string (not a list)?

Copy link
Member

Choose a reason for hiding this comment

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

It looks it would still be a good idea to fix the scalar case?

@@ -462,19 +462,30 @@ def test_interp_like():


@requires_scipy
def test_datetime():
da = xr.DataArray(np.random.randn(24), dims='time',
@pytest.mark.parametrize('x_new, expected', [
Copy link
Member

Choose a reason for hiding this comment

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

I think requires_scipy does not work with another decorator. (We need to improve it though)

A workaround is to pytest.importorskip('scipy') inside the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot to add '@requires_scipy' with the new test

Copy link
Member

Choose a reason for hiding this comment

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

OK. Forget my comment. I will be merging it later.

@fujiisoup fujiisoup merged commit 1ecb6e8 into pydata:master Jul 29, 2018
@fujiisoup
Copy link
Member

Thanks, @dcherian. merging.



@requires_scipy
def test_datetime_single_string():
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shoyer the scalar case works and is tested here. I didn't want to make the previous test too complicated (it fails because the result of the scalar case has no dims; but the test checks both dims and coords).

Copy link
Member

Choose a reason for hiding this comment

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

OK, cool :)

@dcherian dcherian deleted the fix/2284 branch July 30, 2018 00:33
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.

interp over time coordinate
3 participants