# Buggy code
def encode_example(self, audio_or_path_or_fobj):
    if isinstance(audio_or_path_or_fobj, (np.ndarray, list)):
        return audio_or_path_or_fobj
    elif isinstance(audio_or_path_or_fobj, six.string_types):
        filename = audio_or_path_or_fobj
        file_format = self._file_format or filename.split(".")[-1]
        with tf.io.gfile.GFile(filename, "rb") as audio_f:
            return self._encode_file(audio_f, file_format)
    else:
        return self._encode_file(audio_or_path_or_fobj, self._file_format)


# Traceback (RuntimeError)
2020-10-02 00:20:54.722953: I tensorflow_io/core/kernels/cpu_check.cc:128] Your CPU supports instructions that this TensorFlow IO binary was not compiled to use: AVX2 FMA
Running tests under Python 3.7.8: /opt/conda/bin/python3
[ RUN      ] AudioSetTest.test_baseclass
INFO:tensorflow:time(__main__.AudioSetTest.test_baseclass): 0.26s
I1002 00:20:55.194009 140623569565056 test_util.py:1973] time(__main__.AudioSetTest.test_baseclass): 0.26s
[       OK ] AudioSetTest.test_baseclass
[ RUN      ] AudioSetTest.test_download_and_prepare_as_dataset
Total configs: 0
I1002 00:20:55.196529 140623569565056 dataset_builder.py:358] Generating dataset audioset (/tmp/runmulqsrjk/tmp04tb3m6j/audioset/0.1.0)
Downloading and preparing dataset audioset/0.1.0 (download: Unknown size, generated: Unknown size, total: Unknown size) to /tmp/runmulqsrjk/tmp04tb3m6j/audioset/0.1.0...
I1002 00:20:55.240417 140623569565056 dataset_builder.py:988] Generating split train
0 examples [00:00, ? examples/s]2020-10-02 00:20:55.405197: I tensorflow/core/platform/profile_utils/cpu_utils.cc:104] CPU Frequency: 2300000000 Hz
2020-10-02 00:20:55.406191: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55a36ca68a90 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-10-02 00:20:55.406231: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-10-02 00:20:55.406430: I tensorflow/core/common_runtime/process_util.cc:146] Creating new thread pool with default inter op setting: 2. Tune using inter_op_parallelism_threads for best performance.
2020-10-02 00:20:55.407146: W tensorflow/core/framework/op_kernel.cc:1767] OP_REQUIRES failed at whole_file_read_ops.cc:116 : Failed precondition: /home/jupyter/datasets/tensorflow_datasets/testing/test_data/fake_examples/audioset/trimmed_audio/.ipynb_checkpoints; Is a directory
Shuffling and writing examples to /tmp/runmulqsrjk/tmp04tb3m6j/audioset/0.1.0.incompleteWO0GI5/audioset-train.tfrecord
0%|                                                                                                                                                                        | 0/4 [00:00<?, ? examples/s]I1002 00:20:55.907156 140623569565056 tfrecords_writer.py:226] Done writing /tmp/runmulqsrjk/tmp04tb3m6j/audioset/0.1.0.incompleteWO0GI5/audioset-train.tfrecord. Shard lengths: [4]
/opt/conda/lib/python3.7/site-packages/apache_beam/typehints/typehints.py:524: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
if not isinstance(type_params, (collections.Sequence, set)):
I1002 00:20:56.328425 140623569565056 dataset_builder.py:413] Skipping computing stats for mode ComputeStatsMode.SKIP.
Dataset audioset downloaded and prepared to /tmp/runmulqsrjk/tmp04tb3m6j/audioset/0.1.0. Subsequent calls will reuse this data.
I1002 00:20:56.329698 140623569565056 dataset_builder.py:512] Constructing tf.data.Dataset for split train, from /tmp/runmulqsrjk/tmp04tb3m6j/audioset/0.1.0
I1002 00:20:56.386478 140623569565056 dataset_builder.py:512] Constructing tf.data.Dataset for split train, from /tmp/runmulqsrjk/tmp04tb3m6j/audioset/0.1.0
I1002 00:20:56.650481 140623569565056 dataset_info.py:355] Load dataset info from /tmp/runmulqsrjk/tmp04tb3m6j/audioset/0.1.0
I1002 00:20:56.651347 140623569565056 dataset_builder.py:512] Constructing tf.data.Dataset for split train, from /tmp/runmulqsrjk/tmp04tb3m6j/audioset/0.1.0
I1002 00:20:56.678382 140623569565056 dataset_builder.py:512] Constructing tf.data.Dataset for split train, from /tmp/runmulqsrjk/tmp04tb3m6j/audioset/0.1.0
INFO:tensorflow:time(__main__.AudioSetTest.test_download_and_prepare_as_dataset): 1.6s
I1002 00:20:56.796965 140623569565056 test_util.py:1973] time(__main__.AudioSetTest.test_download_and_prepare_as_dataset): 1.6s
WARNING:tensorflow:From /opt/conda/lib/python3.7/contextlib.py:82: TensorFlowTestCase.test_session (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `self.session()` or `self.cached_session()` instead.
W1002 00:20:56.799427 140623569565056 deprecation.py:323] From /opt/conda/lib/python3.7/contextlib.py:82: TensorFlowTestCase.test_session (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `self.session()` or `self.cached_session()` instead.
2020-10-02 00:20:56.800127: I tensorflow/core/common_runtime/process_util.cc:146] Creating new thread pool with default inter op setting: 2. Tune using inter_op_parallelism_threads for best performance.
Total configs: 0
I1002 00:20:56.800700 140623569565056 dataset_builder.py:358] Generating dataset audioset (/tmp/runmulqsrjk/tmp8uycbooq/audioset/0.1.0)
Downloading and preparing dataset audioset/0.1.0 (download: Unknown size, generated: Unknown size, total: Unknown size) to /tmp/runmulqsrjk/tmp8uycbooq/audioset/0.1.0...
I1002 00:20:56.801388 140623569565056 dataset_builder.py:988] Generating split train
INFO:tensorflow:time(__main__.AudioSetTest.test_download_and_prepare_as_dataset): 0.05s
I1002 00:20:56.847491 140623569565056 test_util.py:1973] time(__main__.AudioSetTest.test_download_and_prepare_as_dataset): 0.05s
[  FAILED  ] AudioSetTest.test_download_and_prepare_as_dataset
Exception ignored in: <generator object Audioset._generate_examples at 0x7fe419f3c7d0>
RuntimeError: generator ignored GeneratorExit
[ RUN      ] AudioSetTest.test_info
INFO:tensorflow:time(__main__.AudioSetTest.test_info): 0.0s
I1002 00:20:56.863561 140623569565056 test_util.py:1973] time(__main__.AudioSetTest.test_info): 0.0s
[       OK ] AudioSetTest.test_info
[ RUN      ] AudioSetTest.test_registered
INFO:tensorflow:time(__main__.AudioSetTest.test_registered): 0.0s
I1002 00:20:56.865559 140623569565056 test_util.py:1973] time(__main__.AudioSetTest.test_registered): 0.0s
[       OK ] AudioSetTest.test_registered
[ RUN      ] AudioSetTest.test_session
[  SKIPPED ] AudioSetTest.test_session
======================================================================
ERROR: test_download_and_prepare_as_dataset (__main__.AudioSetTest)
test_download_and_prepare_as_dataset (__main__.AudioSetTest)
Run the decorated test method.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/jupyter/datasets/tensorflow_datasets/testing/test_utils.py", line 341, in decorated
f(self, *args, **kwargs)
File "/home/jupyter/datasets/tensorflow_datasets/testing/dataset_builder_testing.py", line 306, in test_download_and_prepare_as_dataset
self._download_and_prepare_as_dataset(self.builder)
File "/home/jupyter/datasets/tensorflow_datasets/testing/dataset_builder_testing.py", line 370, in _download_and_prepare_as_dataset
builder.download_and_prepare(download_config=download_config)
File "/home/jupyter/datasets/tensorflow_datasets/core/dataset_builder.py", line 388, in download_and_prepare
download_config=download_config)
File "/home/jupyter/datasets/tensorflow_datasets/core/dataset_builder.py", line 1042, in _download_and_prepare
max_examples_per_split=download_config.max_examples_per_split,
File "/home/jupyter/datasets/tensorflow_datasets/core/dataset_builder.py", line 992, in _download_and_prepare
self._prepare_split(split_generator, **prepare_split_kwargs)
File "/home/jupyter/datasets/tensorflow_datasets/core/dataset_builder.py", line 1058, in _prepare_split
example = self.info.features.encode_example(record)
File "/home/jupyter/datasets/tensorflow_datasets/core/features/features_dict.py", line 195, in encode_example
in utils.zip_dict(self._feature_dict, example_dict)
File "/home/jupyter/datasets/tensorflow_datasets/core/features/features_dict.py", line 194, in <dictcomp>
for k, (feature, example_value)
File "/home/jupyter/datasets/tensorflow_datasets/core/features/feature.py", line 605, in encode_example
example_data = np.array(example_data, dtype=np_dtype)
TypeError: __array__() takes 1 positional argument but 2 were given

----------------------------------------------------------------------
Ran 5 tests in 1.928s

FAILED (errors=1, skipped=1)

# Fixed code
def encode_example(self, audio_or_path_or_fobj):
    if isinstance(audio_or_path_or_fobj, (np.ndarray, list)):
        return audio_or_path_or_fobj
    elif isinstance(audio_or_path_or_fobj, six.string_types):
        filename = audio_or_path_or_fobj
        file_format = self._file_format or filename.split(".")[-1]
        with tf.io.gfile.GFile(filename, "rb") as audio_f:
            try:
                return self._encode_file(audio_f, file_format)
            except Exception as e:  # pylint: disable=broad-except
                utils.reraise(e, prefix=f"Error for {filename}: ")
    else:
        return self._encode_file(audio_or_path_or_fobj, self._file_format)