elpaco-escience / scikit-talk

Scikit-talk is an open-source toolkit for processing collections of real-world conversational speech in Python. The toolkit aims to facilitate the exploration of large collections of transcriptions and annotations of conversational interaction.
Apache License 2.0
2 stars 0 forks source link

Fix TypeError in write_csv function #69

Closed liesenf closed 1 week ago

liesenf commented 1 week ago

Bug description: write_csv encounters TypeError when metadata is provided in dict format.

Solution: edited write_csv function that features press_element function that loops over each element and handles lists, dicts, and strings, or "return as is".

Error message:

TypeError Traceback (most recent call last) in <cell line: 2>() 1 # Save the corpus as a .csv file locally ----> 2 Dutch_corpus.write_csv(path = "Dutch_corpus.csv")

8 frames /usr/local/lib/python3.10/dist-packages/sktalk/corpus/write/writer.py in (x) 52 norm = pd.jsonnormalize(data=metadata, sep="") 53 df = pd.DataFrame(norm) ---> 54 df[:] = np.vectorize(lambda x: ', '.join( 55 x) if isinstance(x, list) else x)(df) 56 return df

TypeError: sequence item 0: expected str instance, dict found

Key Changes: Added process_element function: This function handles three cases: List: Joins the elements with ', '. Dictionary: Converts the dictionary to a JSON string using json.dumps. Alternatively, you could convert the dictionary to a custom string format, e.g., by joining key-value pairs with a colon. Other types: Returns the value as-is. Replaced lambda with process_element: The np.vectorize now applies this more robust function to each element in the DataFrame. This approach should resolve the TypeError by correctly handling cases where elements in the DataFrame are dictionaries.

mdingemanse commented 1 week ago

does fixing this issue mean we need a new release to get it out?

liesenf commented 1 week ago

Yes but for pypi that is not too bad