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

Make sure datetime object arrays are converted to datetime64 #2513

Merged
merged 3 commits into from
Oct 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def as_variable(obj, name=None):
'cannot set variable %r with %r-dimensional data '
'without explicit dimension names. Pass a tuple of '
'(dims, data) instead.' % (name, data.ndim))
obj = Variable(name, obj, fastpath=True)
obj = Variable(name, data, fastpath=True)
Copy link
Member

Choose a reason for hiding this comment

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

good catch! I love it when fixes are this simple :)

else:
raise TypeError('unable to convert object into a variable without an '
'explicit list of dimensions: %r' % obj)
Expand Down
5 changes: 5 additions & 0 deletions xarray/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,11 @@ def test_as_variable(self):
ValueError, 'has more than 1-dimension'):
as_variable(expected, name='x')

# test datetime conversion
dt = datetime(1999, 1, 1)
dts = np.array([dt + timedelta(days=x) for x in range(10)])
assert as_variable(dts, 'time').dtype.kind == 'M'

def test_repr(self):
v = Variable(['time', 'x'], [[1, 2, 3], [4, 5, 6]], {'foo': 'bar'})
expected = dedent("""
Expand Down