Fix path construction in Converter.to_file.
This commit is contained in:
@@ -16,7 +16,8 @@ from collections.abc import Callable, Collection
|
||||
from copy import deepcopy
|
||||
from enum import StrEnum, auto
|
||||
from importlib import resources
|
||||
from os import PathLike, path
|
||||
from os import PathLike
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import jsonschema
|
||||
@@ -24,9 +25,8 @@ import pandas as pd
|
||||
import yaml
|
||||
from numpy import nan
|
||||
|
||||
import assets
|
||||
import AuDaGe
|
||||
from AuDaGe import iec
|
||||
from AuDaGe import assets, iec
|
||||
from AuDaGe.formats.controlexpert.xsy import XSYReader
|
||||
from AuDaGe.frame import AuDaGeFrame, Frame
|
||||
|
||||
@@ -294,15 +294,23 @@ class Converter:
|
||||
|
||||
def to_file(self, frame: Frame, file_path: PathLike | str):
|
||||
write_map: dict[str, Callable] = {
|
||||
"csv": frame.to_csv,
|
||||
"xml": frame.to_xml,
|
||||
"xlsx": frame.to_excel,
|
||||
"csv": lambda path, **kwargs: frame.to_csv(
|
||||
path, index=False, **kwargs
|
||||
),
|
||||
"xml": lambda path, **kwargs: frame.to_xml(
|
||||
path, index=False, **kwargs
|
||||
),
|
||||
"xlsx": lambda path, **kwargs: frame.to_excel(
|
||||
path, index=False, **kwargs
|
||||
),
|
||||
"xsy": XSYReader().write,
|
||||
}
|
||||
format = deepcopy(self.spec[YN.FORMAT])
|
||||
if isinstance(format, str):
|
||||
format_kwargs = {}
|
||||
write = write_map[self.spec[YN.FORMAT]]
|
||||
format_name = self.spec[YN.FORMAT]
|
||||
write = write_map[format_name]
|
||||
format_ext = format_name
|
||||
else:
|
||||
format_name = format.pop(YN.NAME)
|
||||
try:
|
||||
@@ -319,8 +327,9 @@ class Converter:
|
||||
export_kwargs = {}
|
||||
format_kwargs = format | export_kwargs
|
||||
write = write_map[format_name]
|
||||
format_ext = f".{format_ext.lstrip('.')}"
|
||||
write(
|
||||
".".join((path.splitext(file_path)[0], format_ext)),
|
||||
Path(file_path).with_suffix(format_ext),
|
||||
**format_kwargs,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user