Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions mathphys/functions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Useful functions."""

import builtins as _builtins
import gzip as _gzip
import os as _os
Expand Down Expand Up @@ -48,7 +49,7 @@ def generate_random_numbers(n_part, dist_type='exp', cutoff=3):
above = above[indcs]

if dist_type in 'uniform':
numbers -= 1/2
numbers -= 1 / 2
numbers *= 2
return numbers

Expand Down Expand Up @@ -289,6 +290,7 @@ def repo_info(repo_path):

def get_path_from_package(package):
"""Return the directory where package is installed.

Args:
package (str or module): Package name or module
Raises:
Expand All @@ -304,7 +306,7 @@ def get_path_from_package(package):
else:
raise ValueError('Invalid package type, must be str or module')
dist = _implib_meta.distribution(pkg)
return str(dist.locate_file("")), dist.version
return str(dist.locate_file('')), dist.version


def is_git_repo(path):
Expand All @@ -325,12 +327,12 @@ def get_package_string(package):
if is_git_repo(path):
info = repo_info(path)
if info['last_tag']:
repo_str += f"{info['last_tag']:s}"
repo_str += f'{info["last_tag"]:s}'
if info['last_tag_commit'] != info['last_commit']:
repo_str += '+' if info['last_tag'] else ''
repo_str += f"{info['last_commit']:s}"
repo_str += f'{info["last_commit"]:s}'
if info['is_dirty']:
repo_str += f"+dirty"
repo_str += '+dirty'
else:
repo_str += f'{ver:s}'
return repo_str
Expand All @@ -350,7 +352,7 @@ def flatten(x):
# ------------------------- HELPER METHODS ------------------------------------
_BUILTINTYPES = (int, float, complex, str, bytes, bool)
_BUILTINNAMES = {typ.__name__ for typ in _BUILTINTYPES}
_NPTYPES = (_np.int_, _np.float_, _np.complex_, _np.bool_)
_NPTYPES = (_np.int_, _np.float64, _np.complex128, _np.bool_)


def _save_recursive_hdf5(fil, path, obj, compress):
Expand All @@ -372,7 +374,7 @@ def _save_recursive_hdf5(fil, path, obj, compress):
for key, item in obj.items():
_save_recursive_hdf5(fil, path + key, item, compress)
else:
raise TypeError('Data type not valid: '+typ.__name__+'.')
raise TypeError('Data type not valid: ' + typ.__name__ + '.')
fil[path].attrs['type'] = typ.__name__


Expand All @@ -383,7 +385,8 @@ def _load_recursive_hdf5(fil):
return [_load_recursive_hdf5(fil[str(i)]) for i in range(len(fil))]
elif typ == 'tuple':
return tuple([
_load_recursive_hdf5(fil[str(i)]) for i in range(len(fil))])
_load_recursive_hdf5(fil[str(i)]) for i in range(len(fil))
])
elif typ == 'set':
return {_load_recursive_hdf5(fil[str(i)]) for i in range(len(fil))}
elif typ == 'dict':
Expand Down