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