Skip to content

Commit 3d11031

Browse files
committed
Merge pull request #568 from shoyer/fix-unicode-variable-indexing
Fixed bug with indexing arrays with unicode dtype
2 parents f26b29a + ecff099 commit 3d11031

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/whats-new.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Bug fixes
3434

3535
- Aggregation functions now correctly skip ``NaN`` for data for ``complex128``
3636
dtype (:issue:`554`).
37+
- Fixed indexing 0d arrays with unicode dtype (:issue:`568`).
3738

3839
v0.6.0 (21 August 2015)
3940
-----------------------

xray/core/variable.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ def _as_compatible_data(data, fastpath=False):
101101
data = np.timedelta64(getattr(data, 'value', data), 'ns')
102102

103103
if (not hasattr(data, 'dtype') or not hasattr(data, 'shape')
104-
or isinstance(data, (np.string_, np.datetime64, np.timedelta64))):
104+
or isinstance(data, (np.string_, np.unicode_,
105+
np.datetime64, np.timedelta64))):
105106
# data must be ndarray-like
106107
data = np.asarray(data)
107108

xray/test/test_variable.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,15 @@ def test_index_0d_numpy_string(self):
599599
v = Variable([], np.string_('asdf'))
600600
self.assertVariableIdentical(v[()], v)
601601

602+
v = Variable([], np.unicode_(u'asdf'))
603+
self.assertVariableIdentical(v[()], v)
604+
605+
def test_indexing_0d_unicode(self):
606+
# regression test for GH568
607+
actual = Variable(('x'), [u'tmax'])[0][()]
608+
expected = Variable((), u'tmax')
609+
self.assertVariableIdentical(actual, expected)
610+
602611
def test_transpose(self):
603612
v = Variable(['time', 'x'], self.d)
604613
v2 = Variable(['x', 'time'], self.d.T)

0 commit comments

Comments
 (0)