Skip to content

Cannot print index returned by audinterface.Segment #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hagenw opened this issue Jun 6, 2023 · 6 comments
Closed

Cannot print index returned by audinterface.Segment #119

hagenw opened this issue Jun 6, 2023 · 6 comments

Comments

@hagenw
Copy link
Member

hagenw commented Jun 6, 2023

Tested with version 1.0.2

import audb
import audinterface

def process_func(signal, sampling_rate):
    return audinterface.utils.signal_index(starts=[0.12], ends=[1.76])

db = audb.load('emodb')
interface = audinterface.Segment(process_func=process_func)
index = interface.process_index(db.files[:2])

But then

>>> index
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/audeering.local/hwierstorf/.envs/test/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 1233, in __repr__
    data = self._format_data()
  File "/home/audeering.local/hwierstorf/.envs/test/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 1275, in _format_data
    return format_object_summary(
  File "/home/audeering.local/hwierstorf/.envs/test/lib/python3.8/site-packages/pandas/io/formats/printing.py", line 436, in format_object_summary
    word = tail_item + sep + " "
TypeError: can only concatenate tuple (not "str") to tuple

When I add the index to a dataframe it can be printed, so maybe this is a pandas error?

>>> pd.DataFrame([0, 0], index=index)
                                                                                                 0
file                                              start                  end                      
/home/audeering.local/hwierstorf/audb/emodb/1.... 0 days 00:00:00.120000 0 days 00:00:01.760000  0
                                                                         0 days 00:00:01.760000  0
@hagenw
Copy link
Member Author

hagenw commented Jun 6, 2023

Indeed, when installing pandas<2.0.0 it returns

>>> index
MultiIndex([('/home/audeering.local/hwierstorf/audb/emodb/1.4.1/d3b62a9b/wav/03a01Fa.wav', ...),
            ('/home/audeering.local/hwierstorf/audb/emodb/1.4.1/d3b62a9b/wav/03a01Nc.wav', ...)],
           names=['file', 'start', 'end'])

@hagenw
Copy link
Member Author

hagenw commented Jun 6, 2023

I can also replicate this when I create the index myself:

import audformat

files = list(db.files[:2])
starts = [0.12, 0.12]
ends = [1.76, 1.76]
index = audformat.segmented_index(files, starts, ends)

and then

>>> index
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/audeering.local/hwierstorf/.envs/test/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 1233, in __repr__
    data = self._format_data()
  File "/home/audeering.local/hwierstorf/.envs/test/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 1275, in _format_data
    return format_object_summary(
  File "/home/audeering.local/hwierstorf/.envs/test/lib/python3.8/site-packages/pandas/io/formats/printing.py", line 436, in format_object_summary
    word = tail_item + sep + " "
TypeError: can only concatenate tuple (not "str") to tuple

@hagenw
Copy link
Member Author

hagenw commented Jun 6, 2023

Interestingly, it seems to depend on the string of the files:

files = ['a', 'b']
starts = [0.12, 0.12]
ends = [1.76, 1.76]
audformat.segmented_index(files, starts, ends)

returns

MultiIndex([('a', '0 days 00:00:00.120000', '0 days 00:00:01.760000'),
            ('b', '0 days 00:00:00.120000', '0 days 00:00:01.760000')],
           names=['file', 'start', 'end'])

@hagenw
Copy link
Member Author

hagenw commented Jun 7, 2023

This was indeed a pandas bug, see pandas-dev/pandas#53537 and should be fixed with a new pandas release.

@hagenw
Copy link
Member Author

hagenw commented Jul 28, 2023

This should be fixed in pandas>=2.1.0.

@hagenw
Copy link
Member Author

hagenw commented Mar 21, 2024

This was indeed fixed in pandas.

@hagenw hagenw closed this as completed Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant