blaze / datashape

Language defining a data description protocol
BSD 2-Clause "Simplified" License
183 stars 65 forks source link

`str` of datashape can't always be parsed by datashape #146

Closed cpcloud closed 9 years ago

cpcloud commented 9 years ago

This doesn't work:

In [19]: from datashape import dshape

In [20]: dshape(str(dshape('{"./abc": int64}')))
DataShapeSyntaxError:

  File <nofile>, line 1
    {./abc: int64}
     ^

DataShapeSyntaxError: Invalid DataShape token

Oddly enough, with spaces after a and after b, it does:

In [20]: dshape(str(dshape('{"./a b c": int64}')))
Out[20]: dshape("{'./a b c': int64}")
eriknw commented 9 years ago

A quick and very naive hack fixes the given example and still passes tests:

diff --git a/datashape/coretypes.py b/datashape/coretypes.py
index d883d8f..ff771e2 100644
--- a/datashape/coretypes.py
+++ b/datashape/coretypes.py
@@ -1360,7 +1360,7 @@ def pprint(ds, width=80):
         ds = ds[-1]

     if isinstance(ds, Record):
-        pairs = ['%s: %s' % (name if ' ' not in name else
+        pairs = ['%s: %s' % (name if ' ' not in name and '/' not in name else
                              repr(print_unicode_string(name)),
                              pprint(typ, width - len(result) - len(name)))
                  for name, typ in zip(ds.names, ds.types)]

I'm not really sure what I'm doing though and what the implications may be. If this ad-hoc approach is reasonable, I can make a PR with a regression test.

cpcloud commented 9 years ago

i've got something already done, just haven't put it up yet