Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Make things a little cleaner and more idiomatic

Co-authored-by: Jacob Wilkins <[email protected]>
  • Loading branch information
ajjackson and oerc0122 committed Sep 19, 2024
1 parent 56dfcb9 commit ade79e1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions euphonic/spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ def _validate_item(self, item: Integral | slice | Sequence[Integral] | np.ndarra
raise IndexError(f'index "{item.stop}" out of range')
return

if not all([isinstance(i, Integral) for i in item]):
if not all(isinstance(i, Integral) for i in item):
raise TypeError(
f'Index "{item}" should be an integer, slice '
f'or sequence of ints')
Expand Down Expand Up @@ -879,9 +879,9 @@ def __add__(self, other: Self) -> Self:

def iter_metadata(self) -> Generator[OneLineData, None, None]:
"""Iterate over metadata dicts of individual spectra from collection"""
common_metadata = dict(
(key, self.metadata[key])
for key in set(self.metadata.keys()) - {"line_data",})
common_metadata = {
key: self.metadata[key]
for key in set(self.metadata.keys()) - {"line_data",}}

line_data = self.metadata.get("line_data")
if line_data is None:
Expand Down Expand Up @@ -1039,7 +1039,7 @@ def to_dict(self) -> Dict[str, Any]:
@classmethod
def from_dict(cls: Self, d: dict) -> Self:
"""Initialise a Spectrum Collection object from dict"""
data_keys = list(f"{dim}_data" for dim in cls._bin_axes)
data_keys = [f"{dim}_data" for dim in cls._bin_axes]
data_keys.append(cls._spectrum_data_name())

d = _process_dict(d,
Expand Down Expand Up @@ -1852,7 +1852,7 @@ def __init__(
f'z_data contains {len(z_data)} spectra, but '
f'metadata["line_data"] contains '
f'{len(metadata["line_data"])} entries')
self.metadata = {} if metadata is None else metadata
self.metadata = metadata if metadata is not None else {}

def _split_by_indices(self, indices: Sequence[int] | np.ndarray
) -> List[Self]:
Expand Down

0 comments on commit ade79e1

Please sign in to comment.