Repository: frictionlessdata/frictionless-py

Issue:
Stop sorting keyed sources as the order is now guaranteed by Python
# Overview

> Standard dict objects preserve order in the reference (CPython) implementations of Python 3.5 and 3.6, and this order-preserving property is becoming a language feature in Python 3.7.

http://gandenberger.org/2018/03/10/ordered-dicts-vs-ordereddict/



Discussion:
roll: Hi @chris48s,

Please take a look. We have discussed this one

Patch:
diff --git a/frictionless/parsers/inline.py b/frictionless/parsers/inline.py
index 7bf834c7..9de663f5 100644
--- a/frictionless/parsers/inline.py
+++ b/frictionless/parsers/inline.py
@@ -1,11 +1,9 @@
 from itertools import chain
-from collections import OrderedDict
 from ..parser import Parser
 from .. import exceptions
 from .. import errors
 
 
-# TODO: add support for a stream front matter? (resource)
 class InlineParser(Parser):
     """Inline parser implementation.
 
@@ -55,8 +53,6 @@ class InlineParser(Parser):
         if isinstance(cells, dict):
             dialect["keyed"] = True
             headers = dialect.keys or list(cells.keys())
-            if not dialect.keys and not isinstance(cells, OrderedDict):
-                headers = sorted(headers)
             yield headers
             for cells in chain([cells], data):
                 if not isinstance(cells, dict):


Test patch:
diff --git a/tests/parsers/test_inline.py b/tests/parsers/test_inline.py
index c5a77033..c9654e64 100644
--- a/tests/parsers/test_inline.py
+++ b/tests/parsers/test_inline.py
@@ -20,6 +20,14 @@ def test_table_inline_keyed():
         assert table.read_data() == [["1", "english"], ["2", "中国人"]]
 
 
+def test_table_inline_keyed_order_is_preserved():
+    source = [{"name": "english", "id": "1"}, {"name": "中国人", "id": "2"}]
+    with Table(source, format="inline") as table:
+        assert table.dialect.keyed is True
+        assert table.header == ["name", "id"]
+        assert table.read_data() == [["english", "1"], ["中国人", "2"]]
+
+
 def test_table_inline_keyed_with_keys_provided():
     source = [{"id": "1", "name": "english"}, {"id": "2", "name": "中国人"}]
     dialect = dialects.InlineDialect(keys=["name", "id"])