Skip to content

Commit

Permalink
discover(object) sniffs for shape/dtype
Browse files Browse the repository at this point in the history
  • Loading branch information
mrocklin committed Feb 8, 2015
1 parent bd36240 commit 7728533
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions datashape/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def discover(o, **kwargs):
See http://datashape.pydata.org/grammar.html#some-simple-examples
for more examples
"""
if hasattr(o, 'shape') and hasattr(o, 'dtype'):
return from_numpy(o.shape, o.dtype)
raise NotImplementedError("Don't know how to discover type %s" %
type(o).__name__)

Expand Down
9 changes: 9 additions & 0 deletions datashape/tests/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,12 @@ def test_letters_only_strings():
'friday', 'saturday', 'a', 'b', 'now', 'yesterday', 'tonight')
for s in strings:
assert discover(s) == string


def test_discover_array_like():
class MyArray(object):
def __init__(self, shape, dtype):
self.shape = shape
self.dtype = dtype

assert discover(MyArray((4, 3), 'f4')) == dshape('4 * 3 * float32')

0 comments on commit 7728533

Please sign in to comment.