tiled icon indicating copy to clipboard operation
tiled copied to clipboard

Let `Container.write_dataframe` accept a dict

Open danielballan opened this issue 1 year ago • 1 comments

It is convenient that Container.write_array accepts a list, like:

$ tiled serve catalog --temp --api-key=secret
In [1]: from tiled.client import from_uri

In [2]: c = from_uri('http://localhost:8000', api_key='secret')

In [3]: c
Out[3]: <Container {}>

In [4]: c.write_array([1,2,3], key='x')
Out[4]: <ArrayClient shape=(3,) chunks=((3,),) dtype=int64>

It would be convenient if

c.write_dataframe({'a': [1,2,3], 'b':, [4,5,6]}, key='y')

were likewise acceptable. Currently, a pandas.DataFrame or dask.dataframe object must be passed.

danielballan avatar May 01 '24 13:05 danielballan

This needs two additions:

  1. Add a branch to this conditional that checks for isinstance(dataframe, dict) and, if so, attempts dataframe = pandas.DataFrame(dataframe).

https://github.com/bluesky/tiled/blob/07c8925746e977352606432743534158972e6da0/tiled/client/container.py#L943-L946

  1. Add a variation on this test that passes the dict data to write_dataframe instead of the pandas.DataFrame df.

https://github.com/bluesky/tiled/blob/07c8925746e977352606432743534158972e6da0/tiled/_tests/test_writing.py#L125-L147

danielballan avatar Jun 27 '24 12:06 danielballan

Closed/addressed via PR above.

nmaytan avatar Aug 06 '24 15:08 nmaytan