Skip to content

Commit

Permalink
Merge pull request #58 from narumiruna/ordereddict
Browse files Browse the repository at this point in the history
Support OrderedDict
  • Loading branch information
narumiruna authored Sep 2, 2022
2 parents 8c2ea5a + 3934cee commit 7bf823e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
9 changes: 6 additions & 3 deletions mlconfig/collections.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class AttrDict(dict):
from collections import OrderedDict


class AttrDict(OrderedDict):
IMMUTABLE = '__immutable__'

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -44,7 +47,7 @@ def is_immutable(self):
return self.__dict__[AttrDict.IMMUTABLE]

def to_dict(self):
data = {}
data = OrderedDict()

for key, value in self.items():
if isinstance(value, AttrDict):
Expand All @@ -55,7 +58,7 @@ def to_dict(self):
return data

def flat(self, prefix=None, sep='.'):
data = {}
data = OrderedDict()

for key, value in self.items():
if prefix is not None:
Expand Down
3 changes: 2 additions & 1 deletion mlconfig/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import copy
import functools
import inspect
from collections import OrderedDict
from string import Template
from typing import Any
from typing import Union
Expand Down Expand Up @@ -84,7 +85,7 @@ def merge_from_file(self, f: str, allow_new_key=False) -> None:


def _flatten(data: dict, prefix=None, sep='.'):
d = {}
d = OrderedDict()

for key, value in data.items():
if prefix is not None:
Expand Down
2 changes: 1 addition & 1 deletion mlconfig/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
from collections.abc import Sequence

import yaml
import oyaml as yaml


def isextension(f: str, ext) -> bool:
Expand Down
35 changes: 25 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ license = "MIT"
[tool.poetry.dependencies]
python = "^3.7"
PyYAML = "^6.0"
oyaml = "^1.0"

[tool.poetry.dev-dependencies]
pytest = "^7.1.2"
Expand Down

0 comments on commit 7bf823e

Please sign in to comment.