Skip to content

Commit

Permalink
Fixed yaml export
Browse files Browse the repository at this point in the history
  • Loading branch information
roll committed Oct 5, 2020
1 parent 00b4387 commit 633e87d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
65 changes: 38 additions & 27 deletions frictionless/helpers.py
Expand Up @@ -245,33 +245,6 @@ def detect_source_scheme_and_format(source):
return (scheme, format)


def get_current_memory_usage():
# Current memory usage of the current process in MB
# This will only work on systems with a /proc file system (like Linux)
# https://stackoverflow.com/questions/897941/python-equivalent-of-phps-memory-get-usage
try:
with open("/proc/self/status") as status:
for line in status:
parts = line.split()
key = parts[0][2:-1].lower()
if key == "rss":
return int(parts[1]) / 1000
except Exception:
pass


class Timer:
def __init__(self):
self.__start = datetime.datetime.now()
self.__stop = None

@property
def time(self):
if not self.__stop:
self.__stop = datetime.datetime.now()
return round((self.__stop - self.__start).total_seconds(), 3)


# Collections


Expand Down Expand Up @@ -370,6 +343,44 @@ def remove(self, *args, **kwargs):
return result


def deepnative(value):
if isinstance(value, dict):
value = {key: deepnative(value) for key, value in value.items()}
elif isinstance(value, list):
value = [deepnative(value) for value in value]
return value


# Measurements


class Timer:
def __init__(self):
self.__start = datetime.datetime.now()
self.__stop = None

@property
def time(self):
if not self.__stop:
self.__stop = datetime.datetime.now()
return round((self.__stop - self.__start).total_seconds(), 3)


def get_current_memory_usage():
# Current memory usage of the current process in MB
# This will only work on systems with a /proc file system (like Linux)
# https://stackoverflow.com/questions/897941/python-equivalent-of-phps-memory-get-usage
try:
with open("/proc/self/status") as status:
for line in status:
parts = line.split()
key = parts[0][2:-1].lower()
if key == "rss":
return int(parts[1]) / 1000
except Exception:
pass


# Backports


Expand Down
2 changes: 1 addition & 1 deletion frictionless/metadata.py
Expand Up @@ -96,7 +96,7 @@ def to_dict(self):
Returns:
dict: metadata as a dict
"""
return self.copy()
return helpers.deepnative(self)

# NOTE: improve this code
def to_json(self, target=None, encoder_class=None):
Expand Down

0 comments on commit 633e87d

Please sign in to comment.