Skip to content

Commit

Permalink
Allow for handling Map types in conversion to numpy dtypes (#224)
Browse files Browse the repository at this point in the history
* Added IDE section to .gitignore

Ignore PyCharm folder

* Handle Map types in conversion to numpy

In the case of Map types only keep the key

Fixes blaze/odo#534

* Fix `test_map` to account for new behaviour
  • Loading branch information
dhirschfeld authored and llllllllll committed Apr 20, 2017
1 parent d2cec59 commit 6cef7af
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -48,3 +48,6 @@ coverage.xml

# Sphinx documentation
docs/_build/

# IDE
.idea/
7 changes: 6 additions & 1 deletion datashape/coretypes.py
Expand Up @@ -364,7 +364,7 @@ class Bytes(Unit):
u'U32': u'U32',
u'utf-32': u'U32',
u'utf_32': u'U32',
u'utf32': u'U32'
u'utf32': u'U32',
}


Expand Down Expand Up @@ -907,6 +907,9 @@ def __str__(self):
self.key,
self.value)

def to_numpy_dtype(self):
return to_numpy_dtype(self)


def _launder(x):
""" Clean up types prior to insertion into DataShape
Expand Down Expand Up @@ -1276,6 +1279,8 @@ def __str__(self):
def to_numpy_dtype(ds):
""" Throw away the shape information and just return the
measure as NumPy dtype instance."""
if isinstance(ds.measure, datashape.coretypes.Map):
ds = ds.measure.key
return to_numpy(ds.measure)[1]


Expand Down
3 changes: 1 addition & 2 deletions datashape/tests/test_coretypes.py
Expand Up @@ -590,8 +590,7 @@ def test_map():
assert fk.value == Record([('a', int32)])
assert fk.value.dict == {'a': int32}
assert fk.value.fields == (('a', int32),)
with pytest.raises(TypeError):
fk.to_numpy_dtype()
assert fk.to_numpy_dtype() == np.dtype('int32')


def test_map_parse():
Expand Down

0 comments on commit 6cef7af

Please sign in to comment.