0

I have a function that if you pass it some data identifier, it will return a pandas dataframe of that dataset. I've just added a new parameter that, when True, returns a second dataframe with metadata about the dataset. So the function can return either one dataset or two, depending on the parameters. But I've found that when the metadata flag is False but the function call asks for two return values, if the dataset has only two columns it will return the dataset column names as strings.

res1, res2 = get_dataframe(dataset_id='123', include_metadata = False) #123 has 2 columns; this call should return 1 dataframe

type(res1)
>>> <class 'str'>

res1
>>> Anonymizing bipartite graph data...

type(res2)
>>> <class 'str'>

res2
>>> The union-split algorithm...

What I want is for this code to throw an error, as it does for datasets with 3 or more columns of data (1 column datasets are not possible).

res1, res2 = get_dataframe(dataset_id='abc', include_metadata = False) #abc has 6 columns; this call should return 1 dataframe

ValueError: too many values to unpack (expected 2)

If I make the call correctly with the two column dataset, it does return either 1 or 2 dataframes.

res = get_dataframe(dataset_id='123', include_metadata = False) #123 has 2 columns; this call should return 1 dataframe

type(res)
>>> <class 'pandas.core.frame.DataFrame'>

res.shape
>>> (5, 2)


res1, res2 = get_dataframe(dataset_id='123', include_metadata = True) #123 has 2 columns; this call should return 2 dataframes

type(res1)
>>> <class 'pandas.core.frame.DataFrame'>

res1.shape
>>> (5, 2)

type(res2)
>>> <class 'pandas.core.frame.DataFrame'>

res2.shape
>>> (8, 2)

So my question is, why does the first example above not throw an error and instead return strings? Thank you in advance for any feedback!

Julia
  • 1
  • 1

0 Answers0