file_dump_json accepts Path - so we should feed it that

This commit is contained in:
Matthias
2019-08-16 13:04:07 +02:00
parent 69eff89049
commit 09286d4918
4 changed files with 16 additions and 14 deletions

View File

@@ -5,11 +5,11 @@ import gzip
import logging
import re
from datetime import datetime
from pathlib import Path
import numpy as np
import rapidjson
logger = logging.getLogger(__name__)
@@ -39,7 +39,7 @@ def datesarray_to_datetimearray(dates: np.ndarray) -> np.ndarray:
return dates.dt.to_pydatetime()
def file_dump_json(filename, data, is_zip=False) -> None:
def file_dump_json(filename: Path, data, is_zip=False) -> None:
"""
Dump JSON data into a file
:param filename: file to create
@@ -49,8 +49,8 @@ def file_dump_json(filename, data, is_zip=False) -> None:
logger.info(f'dumping json to "{filename}"')
if is_zip:
if not filename.endswith('.gz'):
filename = filename + '.gz'
if filename.suffix != '.gz':
filename = filename.with_suffix('.gz')
with gzip.open(filename, 'w') as fp:
rapidjson.dump(data, fp, default=str, number_mode=rapidjson.NM_NATIVE)
else: