Skip to content

Commit

Permalink
Upload version 1.4.5 to pypi. Add write json files + support read jso…
Browse files Browse the repository at this point in the history
…nc files with comments
  • Loading branch information
Florian felice committed Sep 11, 2022
1 parent e33d1a3 commit b4a2b50
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pycof/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from .misc import _get_config as get_config
from .misc import _pycof_folders as pycof_folders

__version__ = '1.4.4'
__version__ = '1.4.5'
18 changes: 18 additions & 0 deletions pycof/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,24 @@ def f_read(path, extension=None, parse=True, remove_comments=True, sep=',', shee
data = json.load(json_file)
else:
data = pd.read_json(path, **kwargs)
elif ext.lower() in ['jsonc']:
if type(path) == BytesIO:
file = path.read().decode()
else:
with open(path) as f:
file = f.read()
for line in file.split('\n'): # Parse the data
l_striped = line.strip()
if remove_comments:
l_striped = re.sub(r"/\*(.|\s|\n)*?\*/", "", l_striped)
l_striped = l_striped.split('//')[0]
l_striped = l_striped.split('#')[0]
if l_striped != '':
data += [l_striped]
str_content = ' '.join(data)
# Ensure there is no comma at the end of the dict
str_content = str_content.replace(", }", "}")
data = json.loads(str_content)
# Parquet
elif ext.lower() in ['parq', 'parquet']:
_engine = 'pyarrow' if engine == 'auto' else engine
Expand Down
6 changes: 5 additions & 1 deletion pycof/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,12 @@ def write(file, path, perm='a', verbose=False, end_row='\n', credentials={}, pro
data_path = os.path.join(_pycof_folders('temp'), 'pycof', 'cache', 'data') + os.sep
path = data_path + file_name


with open(path, perm) as f:
f.write(file + end_row)
if path.endswith('.json') or path.endswith('.jsonc'):
json.dump(file, f)
else:
f.write(file + end_row)

if useIAM:
s3.upload_file(path, bucket, folder_path)
Expand Down
2 changes: 1 addition & 1 deletion setup_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pycof",
version="1.4.4",
version="1.4.5",
author="Florian Felice",
author_email="[email protected]",
description="A package for commonly used functions",
Expand Down

0 comments on commit b4a2b50

Please sign in to comment.