ContinuumIO/datashape — pull request #46 by mrocklin (2014-04-19 02:29:25+00:00)
Title: Predicates

I wanted to check if a datashape represented something was tabular. I.e. that would fit into a SQL database or pandas DataFrame.

```Python
>>> istabular('var * 3 * int')
True
>>> istabular('var * {name: string, amount: int}')
True
>>> istabular('var * 10 * 3 * int')
False
>>> istabular('10 * var * int')
False
```

To do this I built out the following predicates on datashapes:

```Python
>>> isdimension(Var())
True
>>> isdimension(int32)
False
>>> ishomogenous('var * 3 * string')
True
>>> ishomogenous('var * {name: string, amount: int}')
False
>>> dimensions(10 * int32)
1
>>> dimensions('var * 10 * int')
2
>>> isfixed('10 * int')
True
>>> isfixed('var * int')
False
```
As well as a general traversal function

```Python
>>> predicate = lambda term: isinstance(term, Unit)
>>> dshape = dshape('var * {value: int64, loc: 2 * int32}')
>>> sorted(set(collect(predicate, dshape)))
[Fixed(2), ctype("int32"), ctype("int64"), Var()]
```

Code note, this PR is entirely tested by docstrings. Everything passes locally. I think that we should make this an acceptable testing policy because it improves user experience (and I would argue, programming experience.) We do need to get travis to test these though.