Skip to content

Commit

Permalink
Let audb.Dependencies methods return fix types (#27)
Browse files Browse the repository at this point in the history
* Let audb.Dependencies methods return fix types

* Remove if statements

* Remove another if statement

* Update audb/core/dependencies.py

Co-authored-by: Johannes Wagner <[email protected]>

* Update audb/core/dependencies.py

Co-authored-by: Johannes Wagner <[email protected]>

* Update audb/core/dependencies.py

Co-authored-by: Johannes Wagner <[email protected]>

* Update audb/core/dependencies.py

Co-authored-by: Johannes Wagner <[email protected]>

Co-authored-by: Johannes Wagner <[email protected]>
  • Loading branch information
hagenw and frankenjoe authored Apr 9, 2021
1 parent ccc5ac5 commit 7c5d4dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
16 changes: 8 additions & 8 deletions audb/core/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def archive(self, file: str) -> str:
"""
return self[file][define.DependField.ARCHIVE]

def bit_depth(self, file: str) -> typing.Optional[int]:
def bit_depth(self, file: str) -> int:
r"""Bit depth of media file.
Args:
Expand All @@ -234,9 +234,9 @@ def bit_depth(self, file: str) -> typing.Optional[int]:
bit depth
"""
return self[file][define.DependField.BIT_DEPTH] or None
return self[file][define.DependField.BIT_DEPTH]

def channels(self, file: str) -> typing.Optional[int]:
def channels(self, file: str) -> int:
r"""Number of channels of media file.
Args:
Expand All @@ -246,7 +246,7 @@ def channels(self, file: str) -> typing.Optional[int]:
number of channels
"""
return self[file][define.DependField.CHANNELS] or None
return self[file][define.DependField.CHANNELS]

def checksum(self, file: str) -> str:
r"""Checksum of file.
Expand All @@ -260,7 +260,7 @@ def checksum(self, file: str) -> str:
"""
return self[file][define.DependField.CHECKSUM]

def duration(self, file: str) -> typing.Optional[float]:
def duration(self, file: str) -> float:
r"""Duration of file.
Args:
Expand All @@ -270,7 +270,7 @@ def duration(self, file: str) -> typing.Optional[float]:
duration in seconds
"""
return self[file][define.DependField.DURATION] or None
return self[file][define.DependField.DURATION]

def format(self, file: str) -> str:
r"""Format of file.
Expand Down Expand Up @@ -337,7 +337,7 @@ def remove(self, file: str):
"""
self._data[file][define.DependField.REMOVED] = 1

def sampling_rate(self, file: str) -> typing.Optional[int]:
def sampling_rate(self, file: str) -> int:
r"""Sampling rate of media file.
Args:
Expand All @@ -347,7 +347,7 @@ def sampling_rate(self, file: str) -> typing.Optional[int]:
sampling rate in Hz
"""
return self[file][define.DependField.SAMPLING_RATE] or None
return self[file][define.DependField.SAMPLING_RATE]

def save(self, path: str):
r"""Write dependencies to CSV file.
Expand Down
5 changes: 1 addition & 4 deletions audb/core/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def bit_depths(
return set(
[
deps.bit_depth(file) for file in deps.media
if deps.bit_depth(file)
]
)

Expand All @@ -76,7 +75,6 @@ def channels(
return set(
[
deps.channels(file) for file in deps.media
if deps.channels(file)
]
)

Expand Down Expand Up @@ -117,7 +115,7 @@ def duration(
"""
deps = dependencies(name, version=version)
return pd.to_timedelta(
deps()['duration'].sum(),
sum([deps.duration(file) for file in deps.media]),
unit='s',
)

Expand Down Expand Up @@ -333,7 +331,6 @@ def sampling_rates(
return set(
[
deps.sampling_rate(file) for file in deps.media
if deps.sampling_rate(file)
]
)

Expand Down

0 comments on commit 7c5d4dc

Please sign in to comment.