static-frame / frame-fixtures

Use compact expressions to create diverse, deterministic DataFrame fixtures with StaticFrame
Other
8 stars 0 forks source link

GO-ness mismatch could be handled better #8

Open chaburkland opened 1 year ago

chaburkland commented 1 year ago
import frame_fixtures as ff

ff.parse("f(Fg)|s(4, 4)|c(I, str)")                                                                                                                                                                                                                            
---------------------------------------------------------------------------
ErrorInitFrame                            Traceback (most recent call last)
<ipython-input-1-525dac2ecbdb> in <module>
----> 1 ff.parse("f(Fg)|s(4, 4)|c(I, str)")

~/.env38/lib/python3.8/site-packages/frame_fixtures/core.py in parse(dsl)
    730     Given a FrameFixtures DSL string, return a Fraem.
    731     '''
--> 732     return Fixture.parse(dsl=dsl)
    733 
    734 

~/.env38/lib/python3.8/site-packages/frame_fixtures/core.py in parse(cls, dsl, module_sf)
    715             builder = str_to_type['F']
    716 
--> 717         return builder(tb, #type: ignore
    718                 index=index,
    719                 columns=columns,

~/.env38/lib/python3.8/site-packages/static_frame/core/frame.py in __init__(self, data, index, columns, name, index_constructor, columns_constructor, own_data, own_index, own_columns)
   3318         # check after creation, as we cannot determine from the constructor (it might be a method on a class)
   3319         if self._COLUMNS_CONSTRUCTOR.STATIC != self._columns.STATIC:
-> 3320             raise ErrorInitFrame(f'Supplied `columns_constructor` does not match required static attribute: {self._COLUMNS_CONSTRUCTOR.STATIC}')
   3321 
   3322         #-----------------------------------------------------------------------

ErrorInitFrame: Supplied `columns_constructor` does not match required static attribute: False

This is fixed by changing the type of columns to IndexGO, like so:

ff.parse("f(Fg)|s(4, 4)|c(Ig, str)")

I feel the error message for this could be more helpful/clear. Something like:

`FrameFixtureSyntaxError: object type is `FrameGO`, but columns are specified as `Index`. Either change f(Fg) -> f(F), or c(I) -> c(Ig)`