• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ZJU-SPAIL / pipa / 22699554347

05 Mar 2026 02:33AM UTC coverage: 19.922% (-50.1%) from 70.041%
22699554347

push

github

Rui Hu
Merge github/main, resolve two version conflicts by keeping gitlab local

6 of 2484 new or added lines in 35 files covered. (0.24%)

871 of 4372 relevant lines covered (19.92%)

0.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/pipa/parser/_base_sar_parser.py
NEW
1
from __future__ import annotations
×
2

NEW
3
from io import StringIO
×
NEW
4
from pathlib import Path
×
5

NEW
6
import pandas as pd
×
7

8

NEW
9
def _read_file_lines(file_path: Path) -> list[str]:
×
NEW
10
    with open(file_path, "r", errors="ignore") as file_handle:
×
NEW
11
        return file_handle.readlines()
×
12

13

NEW
14
def _reconstruct_csv_content(lines: list[str]) -> tuple[str | None, int]:
×
NEW
15
    header_line_content = None
×
NEW
16
    data_start_index = 0
×
17

NEW
18
    for index, line in enumerate(lines):
×
NEW
19
        if line.strip().startswith("#"):
×
NEW
20
            header_line_content = line.strip()[1:].strip()
×
NEW
21
            data_start_index = index + 1
×
NEW
22
            break
×
23

NEW
24
    return header_line_content, data_start_index
×
25

26

NEW
27
def generic_sar_parse(file_path: Path) -> pd.DataFrame:
×
28
    """Parse sar-generated CSV files into a :class:`pandas.DataFrame`.
29

30
    The collector emits CSV data whose first non-empty line starts with ``#``.
31
    The actual header row is encoded after the hash symbol, followed by rows of
32
    semicolon-separated values. This helper reconstructs the proper CSV content
33
    before handing it to :func:`pandas.read_csv`.
34

35
    Parameters
36
    ----------
37
    file_path:
38
        The CSV file produced by ``sadf -d``.
39

40
    Returns
41
    -------
42
    pandas.DataFrame
43
        DataFrame containing the parsed data. Empty if the file is missing or
44
        0 bytes long.
45
    """
46

NEW
47
    if not file_path.exists() or file_path.stat().st_size == 0:
×
NEW
48
        return pd.DataFrame()
×
49

NEW
50
    lines = _read_file_lines(file_path)
×
NEW
51
    header_line_content, data_start_index = _reconstruct_csv_content(lines)
×
52

NEW
53
    if not header_line_content:
×
NEW
54
        return pd.read_csv(file_path, sep=";")
×
55

NEW
56
    csv_content = header_line_content + "\n" + "".join(lines[data_start_index:])
×
NEW
57
    return pd.read_csv(StringIO(csv_content), sep=";")
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc