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

DIGNEA / DIGNEApy / 18938519862

30 Oct 2025 11:05AM UTC coverage: 87.977% (+4.2%) from 83.754%
18938519862

push

github

amarrerod
✅ Integrates Numpy as a primary data structure

171 of 211 new or added lines in 19 files covered. (81.04%)

11 existing lines in 7 files now uncovered.

2122 of 2412 relevant lines covered (87.98%)

1.76 hits per line

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

26.32
/digneapy/utils/save_data.py
1
#!/usr/bin/env python
2
# -*-coding:utf-8 -*-
3
"""
4
@File    :   save_data.py
5
@Time    :   2025/04/03 10:02:16
6
@Author  :   Alejandro Marrero
7
@Version :   1.0
8
@Contact :   amarrerd@ull.edu.es
9
@License :   (C)Copyright 2025, Alejandro Marrero
10
@Desc    :   None
11
"""
12

13
from collections.abc import Sequence
2✔
14
from typing import Literal, Optional
2✔
15

16
import pandas as pd
2✔
17

18
from digneapy.generators import GenResult
2✔
19

20

21
def save_results_to_files(
2✔
22
    filename_pattern: str,
23
    result: GenResult,
24
    only_instances: bool = True,
25
    only_genotypes: bool = False,
26
    solvers_names: Optional[Sequence[str]] = None,
27
    features_names: Optional[Sequence[str]] = None,
28
    vars_names: Optional[Sequence[str]] = None,
29
    files_format: Literal["csv", "parquet"] = "parquet",
30
):
31
    """Saves the results of the generation to CSV files.
32
    Args:
33
        filename_pattern (str): Pattern for the filenames.
34
        result (GenResult): Result of the generation.
35
        only_instances (bool): Generate only the files with the resulting instances. Default True. If False, it would generate an history and arhice_metrics files.
36
        only_genotypes (bool): Extract only the genotype of each instance. Default False (extracts features and portfolio scores).
37
        solvers_names (Sequence[str]): Names of the solvers.
38
        features_names (Sequence[str]): Names of the features.
39
        vars_names (Sequence[str]): Names of the variables.
40
        files_format (Literal[str] = "csv" or "parquet"): Format to store the resulting instances file.
41
            Parquet is the most efficient for large datasets.
42
    """
43
    if files_format not in ("csv", "parquet"):
×
UNCOV
44
        print(f"Unrecognised file format: {files_format}. Selecting parquet.")
×
UNCOV
45
        files_format = "parquet"
×
UNCOV
46
    df = pd.DataFrame(
×
47
        [
48
            i.to_series(
49
                only_genotype=only_genotypes,
50
                variables_names=vars_names,
51
                features_names=features_names,
52
                score_names=solvers_names,
53
            )
54
            for i in result.instances
55
        ]
56
    )
57
    if not df.empty:
×
58
        df.insert(0, "target", result.target)
×
NEW
59
        if files_format == "csv":
×
NEW
60
            df.to_csv(f"{filename_pattern}_instances.csv", index=False)
×
NEW
61
        elif files_format == "parquet":
×
NEW
62
            df.to_parquet(f"{filename_pattern}_instances.parquet", index=False)
×
63

NEW
64
    if not only_instances:
×
NEW
65
        result.history.to_df().to_csv(f"{filename_pattern}_history.csv", index=False)
×
NEW
66
        if result.metrics is not None:
×
NEW
67
            result.metrics.to_csv(f"{filename_pattern}_archive_metrics.csv")
×
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