tensorflow / tensorflow/datasets

tfds.as_dataframe throws an exception

Open
#3,323 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
4.6k
Forks
1.6k
Avg merge
3h 54m
Merged PRs (30d)
1

Description

/!\ IF YOU WANT PEOPLE TO HELP YOU, PLEASE GIVE AS MUCH DETAIL AS POSSIBLE, INCLUDING THE FULL STACKTRACE AND CODE SNIPPET

Short description
Calling tfds.as_dataframe on the coco_captions dataset returns an error having to do with the constructor

Environment information

  • Operating System: Windows 10

  • Python version: 3.7.10

  • tensorflow-datasets/tfds-nightly version: 4.3.0

  • tensorflow/tf-nightly version: 2.5.0

  • Does the issue still exists with the last tfds-nightly package (pip install --upgrade tfds-nightly) ?
    Yes
    Reproduction instructions

import tensorflow_datasets as tfds
(coco_train, coco_val, coco_test), coco_info = tfds.load('coco_captions', split=['train','val','test'], with_info=True)
df = tfds.as_dataframe(coco_train.take(10), coco_info)

Link to logs
Leads to:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-320-2a3721f476e4> in <module>
----> 1 df = tfds.as_dataframe(coco_val.take(10))
      2 df.head()

~\Anaconda3\envs\RoastBot\lib\site-packages\tensorflow_datasets\core\as_dataframe.py in as_dataframe(ds, ds_info)
    220   columns = _make_columns(ds.element_spec, ds_info=ds_info)
    221   rows = [_make_row_dict(ex, columns) for ex in dataset_utils.as_numpy(ds)]
--> 222   df = StyledDataFrame(rows)
    223   df.current_style.format({c.name: c.format_fn for c in columns if c.format_fn})
    224   return df

~\Anaconda3\envs\RoastBot\lib\site-packages\tensorflow_datasets\core\as_dataframe.py in __init__(self, *args, **kwargs)
    146 
    147   def __init__(self, *args, **kwargs):
--> 148     super().__init__(*args, **kwargs)
    149     # Use name-mangling for forward-compatibility in case pandas
    150     # adds a `_styler` attribute in the future.

TypeError: object.__init__() takes exactly one argument (the instance to initialize)

Expected behavior
df should be a pandas dataframe.

Additional context
Add any other context about the problem here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in tensorflow_datasets/core/as_dataframe.py at StyledDataFrame.init and the as_dataframe call shown in the traceback. Reproduce the coco_captions example, inspect the constructor failure, and verify that tfds.as_dataframe returns a pandas dataframe without the TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.