Skip to content

Commit

Permalink
Fix codespell and ruff errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Jul 11, 2023
1 parent e3dad60 commit fb1c906
Show file tree
Hide file tree
Showing 23 changed files with 126 additions and 174 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ and the `format specifications`_ as a starting point.
.. |tests| image:: https://github.com/audeering/audformat/workflows/Test/badge.svg
:target: https://github.com/audeering/audformat/actions?query=workflow%3ATest
:alt: Test status
.. |coverage| image:: https://codecov.io/gh/audeering/audformat/branch/master/graph/badge.svg?token=1FEG9P5XS0
.. |coverage| image:: https://codecov.io/gh/audeering/audformat/branch/main/graph/badge.svg?token=1FEG9P5XS0
:target: https://codecov.io/gh/audeering/audformat/
:alt: code coverage
.. |docs| image:: https://img.shields.io/pypi/v/audformat?label=docs
:target: https://audeering.github.io/audformat/
:alt: audformat's documentation
.. |license| image:: https://img.shields.io/badge/license-MIT-green.svg
:target: https://github.com/audeering/audformat/blob/master/LICENSE
:target: https://github.com/audeering/audformat/blob/main/LICENSE
:alt: audformat's MIT license
.. |python-versions| image:: https://img.shields.io/pypi/pyversions/audformat.svg
:target: https://pypi.org/project/audformat/
Expand Down
22 changes: 9 additions & 13 deletions audformat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@
from audformat.core.attachment import Attachment
from audformat.core.column import Column
from audformat.core.database import Database
from audformat.core.index import (
assert_index,
assert_no_duplicates,
filewise_index,
index_type,
is_filewise_index,
is_segmented_index,
segmented_index,
)
from audformat.core.index import assert_index
from audformat.core.index import assert_no_duplicates
from audformat.core.index import filewise_index
from audformat.core.index import index_type
from audformat.core.index import is_filewise_index
from audformat.core.index import is_segmented_index
from audformat.core.index import segmented_index
from audformat.core.media import Media
from audformat.core.rater import Rater
from audformat.core.scheme import Scheme
from audformat.core.split import Split
from audformat.core.table import (
MiscTable,
Table,
)
from audformat.core.table import MiscTable
from audformat.core.table import Table


# Discourage from audformat import *
Expand Down
7 changes: 2 additions & 5 deletions audformat/core/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
import typing

import audeer

from audformat.core.common import (
HeaderBase,
is_relative_path,
)
from audformat.core.common import HeaderBase
from audformat.core.common import is_relative_path


class Attachment(HeaderBase):
Expand Down
10 changes: 5 additions & 5 deletions audformat/core/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

from audformat.core import define
from audformat.core.common import HeaderBase
from audformat.core.index import (
index_type,
is_scalar,
to_array,
)
from audformat.core.index import index_type
from audformat.core.index import is_scalar
from audformat.core.index import to_array
from audformat.core.rater import Rater
from audformat.core.typing import Values


if typing.TYPE_CHECKING:
# Fix to make mypy work without circular imports,
# compare
Expand Down Expand Up @@ -365,6 +364,7 @@ def __eq__(
self,
other: 'Column',
) -> bool:
r"""Compare if column equals another column."""
if self.dump() != other.dump():
return False
if self._table is not None and other._table is not None:
Expand Down
14 changes: 6 additions & 8 deletions audformat/core/common.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
from collections import OrderedDict
import inspect
import os
import oyaml as yaml
import typing
import textwrap
from collections import OrderedDict
import typing

import oyaml as yaml
import pandas as pd

from audformat import define
from audformat.core.errors import (
BadKeyError,
BadTypeError,
BadValueError,
)
from audformat.core.errors import BadKeyError
from audformat.core.errors import BadTypeError
from audformat.core.errors import BadValueError


class HeaderDict(OrderedDict):
Expand Down
30 changes: 13 additions & 17 deletions audformat/core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,32 @@
import typing

import oyaml as yaml


try:
from yaml import CLoader as Loader
except ImportError: # pragma: nocover
from yaml import Loader
import pandas as pd

import audeer
import audiofile

from audformat.core import define
from audformat.core import utils
from audformat.core.attachment import Attachment
from audformat.core.column import Column
from audformat.core.common import (
is_relative_path,
HeaderBase,
HeaderDict,
)
from audformat.core.errors import (
BadKeyError,
BadIdError,
TableExistsError,
)
from audformat.core.common import HeaderBase
from audformat.core.common import HeaderDict
from audformat.core.common import is_relative_path
from audformat.core.errors import BadIdError
from audformat.core.errors import BadKeyError
from audformat.core.errors import TableExistsError
from audformat.core.media import Media
from audformat.core.rater import Rater
from audformat.core.scheme import Scheme
from audformat.core.split import Split
from audformat.core.table import (
MiscTable,
Table,
)
from audformat.core.table import MiscTable
from audformat.core.table import Table
import audiofile


class Database(HeaderBase):
Expand Down Expand Up @@ -658,7 +653,6 @@ def update(
RuntimeError: if any involved database is not portable
"""

if isinstance(others, Database):
others = [others]

Expand Down Expand Up @@ -903,6 +897,7 @@ def __eq__(
self,
other: 'Database',
) -> bool:
r"""Comparison if database equals another database."""
if self.dump() != other.dump():
return False
for table_id in list(self.tables) + list(self.misc_tables):
Expand All @@ -913,6 +908,7 @@ def __eq__(
def __iter__(
self,
) -> typing.Union[MiscTable, Table]:
r"""Iterate over (miscellaneous) tables of database."""
yield from sorted(list(self.tables) + list(self.misc_tables))

def __setitem__(
Expand Down
10 changes: 4 additions & 6 deletions audformat/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@

from audformat.core import define
from audformat.core import utils
from audformat.core.typing import (
Files,
Timestamps,
)
from audformat.core.typing import Files
from audformat.core.typing import Timestamps


def is_scalar(value: typing.Any) -> bool:
r"""Check if value is scalar"""
r"""Check if value is scalar."""
return (value is not None) and \
(isinstance(value, str) or not hasattr(value, '__len__'))

Expand Down Expand Up @@ -52,7 +50,7 @@ def assert_index(
ValueError: if not conform to
:ref:`table specifications <data-tables:Tables>`
"""
""" # noqa: D205
if isinstance(obj, (pd.Series, pd.DataFrame)):
obj = obj.index

Expand Down
9 changes: 2 additions & 7 deletions audformat/core/scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@

import pandas as pd

from audformat.core import (
common,
define,
)
from audformat.core import common
from audformat.core import define


class Scheme(common.HeaderBase):
Expand Down Expand Up @@ -186,7 +184,6 @@ def is_numeric(self) -> bool:
def labels_as_list(self) -> typing.List:
r"""Scheme labels as list.
If scheme does not define labels
an empty list is returned.
Expand Down Expand Up @@ -394,7 +391,6 @@ def _check_labels(
labels: typing.Union[dict, list, str],
):
r"""Raise label related errors."""

if not isinstance(labels, (dict, list, str)):
raise ValueError(
'Labels must be passed '
Expand Down Expand Up @@ -450,7 +446,6 @@ def _dtype_from_labels(
labels: typing.Union[dict, list, str],
) -> str:
r"""Derive audformat dtype from labels."""

if isinstance(labels, str):
# misc table
# dtype is stored in the levels dictionary
Expand Down
35 changes: 13 additions & 22 deletions audformat/core/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,25 @@
import pandas as pd

import audeer

from audformat.core import define
from audformat.core import utils
from audformat.core.column import Column
from audformat.core.common import (
HeaderBase,
HeaderDict,
to_audformat_dtype,
to_pandas_dtype,
)
from audformat.core.errors import (
BadIdError,
)
from audformat.core.index import (
filewise_index,
index_type,
is_filewise_index,
is_segmented_index,
)
from audformat.core.common import HeaderBase
from audformat.core.common import HeaderDict
from audformat.core.common import to_audformat_dtype
from audformat.core.common import to_pandas_dtype
from audformat.core.errors import BadIdError
from audformat.core.index import filewise_index
from audformat.core.index import index_type
from audformat.core.index import is_filewise_index
from audformat.core.index import is_segmented_index
from audformat.core.media import Media
from audformat.core.split import Split
from audformat.core.typing import (
Values,
)
from audformat.core.typing import Values


class Base(HeaderBase):
r"""Table base class"""
r"""Table base class."""
def __init__(
self,
index: pd.Index = None,
Expand Down Expand Up @@ -119,11 +110,13 @@ def __eq__(
self,
other: Base,
) -> bool:
r"""Compare if table equals other table."""
if self.dump() != other.dump():
return False
return self.df.equals(other.df)

def __len__(self) -> int:
r"""Number of rows in table."""
return len(self.df)

def __setitem__(self, column_id: str, column: Column) -> Column:
Expand All @@ -143,7 +136,6 @@ def __setitem__(self, column_id: str, column: Column) -> Column:
is already used by the same or another scheme
"""

if (
column.scheme_id is not None
and self.db is not None
Expand Down Expand Up @@ -1555,7 +1547,6 @@ def _assert_table_index(
operation: str,
):
r"""Raise error if index does not match table."""

if isinstance(table, Table):
input_type = index_type(index)
if table.type != input_type:
Expand Down
33 changes: 13 additions & 20 deletions audformat/core/testing.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
import os
import random
from typing import (
Union,
Sequence,
Callable,
Dict,
Tuple,
Optional,
)
from typing import Callable
from typing import Dict
from typing import Optional
from typing import Sequence
from typing import Tuple
from typing import Union
import warnings

import numpy as np
import pandas as pd

import audeer
import audiofile as af

from audformat.core import define
from audformat.core.attachment import Attachment
from audformat.core.column import Column
from audformat.core.database import Database
from audformat.core.index import (
filewise_index,
is_filewise_index,
is_segmented_index,
segmented_index,
)
from audformat.core.index import filewise_index
from audformat.core.index import is_filewise_index
from audformat.core.index import is_segmented_index
from audformat.core.index import segmented_index
from audformat.core.media import Media
from audformat.core.rater import Rater
from audformat.core.scheme import Scheme
from audformat.core.split import Split
from audformat.core.table import (
MiscTable,
Table,
)
from audformat.core.table import MiscTable
from audformat.core.table import Table
import audiofile as af


def add_misc_table(
Expand Down
1 change: 0 additions & 1 deletion audformat/core/typing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import typing


import numpy as np
import pandas as pd

Expand Down
Loading

0 comments on commit fb1c906

Please sign in to comment.