Passed
Push — main ( ec3fe3...82dd22 )
by Douglas
02:00
created

mandos.model.hit_utils.HitUtils.hits_to_df()   A

Complexity

Conditions 2

Size

Total Lines 9
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nop 2
dl 0
loc 9
rs 9.95
c 0
b 0
f 0
1
from typing import Sequence
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
3
import pandas as pd
0 ignored issues
show
introduced by
Unable to import 'pandas'
Loading history...
4
5
from mandos.model.hits import AbstractHit, HitFrame
6
from mandos.model.concrete_hits import HIT_CLASSES
7
8
9
class HitUtils:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
10
    @classmethod
11
    def hits_to_df(cls, hits: Sequence[AbstractHit]) -> HitFrame:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
12
        data = []
13
        for hit in hits:
14
            x = {f: getattr(hit, f) for f in hit.__class__.fields()}
0 ignored issues
show
Coding Style Naming introduced by
Variable name "x" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
15
            x["universal_id"] = hit.universal_id
16
            x["hit_class"] = hit.hit_class
17
            data.append(x)
18
        return HitFrame([pd.Series(x) for x in data])
19
20
    @classmethod
21
    def df_to_hits(cls, self: HitFrame) -> Sequence[AbstractHit]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
22
        hits = []
23
        for row in self.itertuples():
24
            clazz = HIT_CLASSES[row.hit_class]
25
            # ignore extra columns
26
            # if cols are missing, let it fail on clazz.__init__
27
            data = {f: getattr(row, f) for f in clazz.fields()}
28
            # noinspection PyArgumentList
29
            hit = clazz(**data)
30
            hits.append(hit)
31
        return hits
32
33
34
__all__ = ["HitUtils"]
35