Skip to content
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

Remove 3.8 syntax #41

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions auglib/core/interface.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import collections
import os
import typing

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -140,10 +142,10 @@ def __init__(
*,
sampling_rate: int = None,
resample: bool = False,
channels: typing.Union[int, typing.Sequence[int]] = None,
channels: int | collections.abc.Sequence[int] = None,
mixdown: bool = False,
keep_nat: bool = False,
num_workers: typing.Optional[int] = 1,
num_workers: int | None = 1,
multiprocessing: bool = False,
seed: int = None,
verbose: bool = False,
Expand Down Expand Up @@ -184,15 +186,15 @@ def short_id(

def augment(
hagenw marked this conversation as resolved.
Show resolved Hide resolved
self,
data: typing.Union[pd.Index, pd.Series, pd.DataFrame],
data: pd.Index | pd.Series | pd.DataFrame,
cache_root: str = None,
*,
data_root: str = None,
remove_root: str = None,
modified_only: bool = True,
num_variants: int = 1,
force: bool = False,
) -> typing.Union[pd.Index, pd.Series, pd.DataFrame]:
) -> pd.Index | pd.Series | pd.DataFrame:
r"""Augment an index, column, or table conform to audformat.

Creates ``num_variants`` copies of the segments referenced in the index
Expand Down Expand Up @@ -505,10 +507,10 @@ def _apply_nat_mask(


def _augmented_files(
files: typing.Sequence[str],
files: collections.abc.Sequence[str],
cache_root: str,
remove_root: str = None,
) -> typing.List[str]:
) -> list[str]:
r"""Return destination path for augmented files.

If files contain the same filename several times,
Expand Down
18 changes: 10 additions & 8 deletions auglib/core/observe.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import collections
import random
import typing

import numpy as np

Expand All @@ -13,7 +15,7 @@ class Base(audobject.Object):

"""

def __call__(self) -> typing.Any: # pragma: no cover
def __call__(self) -> object: # pragma: no cover
r"""Observe next value.

Returns:
Expand Down Expand Up @@ -227,7 +229,7 @@ class List(Base):
)
def __init__(
self,
elements: typing.MutableSequence[typing.Any],
elements: collections.abc.MutableSequence[object],
*,
shuffle: bool = False,
draw: bool = False,
Expand All @@ -241,10 +243,10 @@ def __init__(
self._counter = 0
self._iter = False

def _draw(self) -> typing.Any:
def _draw(self) -> object:
return self.elements[random.randint(0, len(self) - 1)]

def _next(self) -> typing.Any:
def _next(self) -> object:
if self.shuffle and self._counter == 0:
random.shuffle(self.elements)
element = self.elements[self._counter]
Expand All @@ -254,7 +256,7 @@ def _next(self) -> typing.Any:
self._iter = False
return element

def __call__(self) -> typing.Any:
def __call__(self) -> object:
r"""Observe next value from list.

Returns:
Expand All @@ -281,8 +283,8 @@ def __next__(self): # noqa: D105


def observe(
x: typing.Union[typing.Any, Base],
) -> typing.Any:
x: object | Base,
) -> object:
r"""Convenient function to observe a value.

Returns ``x()`` if ``x`` is of type :class:`auglib.observe.Base`,
Expand Down
18 changes: 9 additions & 9 deletions auglib/core/resolver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import typing
import collections

import numpy as np

Expand All @@ -10,14 +10,14 @@ class ArrayResolver(audobject.resolver.Base):

def decode(
self,
value: typing.Any,
) -> typing.Any:
value: object,
) -> object:
return value

def encode(
self,
value: typing.Any,
) -> typing.Any:
value: object,
) -> object:
if isinstance(value, np.ndarray):
raise ValueError(
f"Cannot serialize an instance of "
Expand All @@ -37,14 +37,14 @@ class ObservableListResolver(audobject.resolver.Base):

def decode(
self,
value: typing.Any,
) -> typing.Any:
value: object,
) -> object:
return value

def encode(
self,
value: typing.MutableSequence[typing.Any],
) -> typing.Any:
value: collections.abc.MutableSequence[object],
) -> object:
for v in value:
if isinstance(v, np.ndarray):
raise ValueError(
Expand Down
4 changes: 2 additions & 2 deletions auglib/core/time.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import typing
from __future__ import annotations

import pandas as pd

Expand Down Expand Up @@ -43,7 +43,7 @@ class Time(audobject.Object):

def __init__(
self,
value: typing.Union[int, float, observe.Base],
value: int | float | observe.Base,
unit: str,
):
self.value = value
Expand Down
Loading
Loading