Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unflatten: Stream all unflattening. #377

Open
wants to merge 2 commits into
base: 315-lower-memory-usage
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
- run: py.test --cov .
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: coveralls
run: coveralls --service=github
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

- flattening: Uses much less memory by storing data in a embedded ZODB database, using ijson and using write only mode in pyopenxl.
- use-titles: Use $ref'erring title if available https://github.com/OpenDataServices/flatten-tool/pull/368
- create-template --no-deprecated-fields: Did not work if deprecated element at same level as a $ref https://github.com/OpenDataServices/flatten-tool/issues/185#issuecomment-719587348

Expand Down
38 changes: 19 additions & 19 deletions examples/bods/unflatten/expected/out.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
[
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the indentation mismatch here between this opening { and the closing one. All the other examples look okay, so I think this has to do with having a list at the root.

Copy link
Member

@Bjwebb Bjwebb Mar 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is a jsonstreams bug, I can reproduce with:

import jsonstreams

with jsonstreams.Stream(jsonstreams.Type.array, filename='test.json', indent=4) as s:
    s.write({"a": 1, "b": 2})

I will report this upstream. Happy to see this merged as is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"statementID": "fbfd0547-d0c6-4a00-b559-5c5e91c34f5c",
"interests": [
{
"type": "shareholding",
"interestLevel": "direct",
"beneficialOwnershipOrControl": true,
"startDate": "2016-04-06",
"share": {
"exact": 100
}
"statementID": "fbfd0547-d0c6-4a00-b559-5c5e91c34f5c",
"interests": [
{
"type": "shareholding",
"interestLevel": "direct",
"beneficialOwnershipOrControl": true,
"startDate": "2016-04-06",
"share": {
"exact": 100
}
],
"statementType": "ownershipOrControlStatement",
"statementDate": "2017-11-18",
"subject": {
"describedByEntityStatement": "1dc0e987-5c57-4a1c-b3ad-61353b66a9b7"
},
"interestedParty": {
"describedByPersonStatement": "019a93f1-e470-42e9-957b-03559861b2e2"
}
],
"statementType": "ownershipOrControlStatement",
"statementDate": "2017-11-18",
"subject": {
"describedByEntityStatement": "1dc0e987-5c57-4a1c-b3ad-61353b66a9b7"
},
"interestedParty": {
"describedByPersonStatement": "019a93f1-e470-42e9-957b-03559861b2e2"
}
]
}
]
8 changes: 4 additions & 4 deletions examples/cafe/relationship-missing-ids/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
}
]
},
{
"name": "Vegetarian Cafe",
"address": "42 Town Road, Bristol"
},
{
"id": "CAFE-VEG",
"table": [
Expand All @@ -24,10 +28,6 @@
}
]
},
{
"name": "Vegetarian Cafe",
"address": "42 Town Road, Bristol"
},
{
"table": [
{
Expand Down
113 changes: 56 additions & 57 deletions examples/iati/expected.xml
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
<?xml version='1.0' encoding='utf-8'?>
<iati-activities>
<!--XML generated by flatten-tool-->
<iati-activity>
<iati-identifier>AA-AAA-123456789-ABC123</iati-identifier>
<reporting-org ref="AA-AAA-123456789" type="40">
<narrative>Organisation name</narrative>
</reporting-org>
<title>
<narrative>A title</narrative>
</title>
<description>
<narrative>A description</narrative>
</description>
<participating-org ref="AA-AAA-123456789" role="1"/>
<activity-status code="2"/>
<activity-date iso-date="2011-10-01" type="1"/>
<recipient-country code="AF" percentage="40"/>
<recipient-country code="XK" percentage="60"/>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2012-01-01"/>
<value value-date="2012-01-01">10</value>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2012-03-03"/>
<value value-date="2012-03-03">20</value>
</transaction>
</iati-activity>
<iati-activity>
<iati-identifier>AA-AAA-123456789-ABC124</iati-identifier>
<reporting-org ref="AA-AAA-123456789" type="40">
<narrative>Organisation name</narrative>
</reporting-org>
<title>
<narrative>Another title</narrative>
</title>
<description>
<narrative>Another description</narrative>
</description>
<participating-org ref="AA-AAA-123456789" role="1"/>
<activity-status code="3"/>
<activity-date iso-date="2016-01-01" type="2"/>
<recipient-country code="AG" percentage="30"/>
<recipient-country code="XK" percentage="70"/>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2013-04-04"/>
<value value-date="2013-04-04">30</value>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2013-05-05"/>
<value value-date="2013-05-05">40</value>
</transaction>
</iati-activity>
</iati-activities>
<iati-activities><!--XML generated by flatten-tool-->
<iati-activity>
<iati-identifier>AA-AAA-123456789-ABC123</iati-identifier>
<reporting-org ref="AA-AAA-123456789" type="40">
<narrative>Organisation name</narrative>
</reporting-org>
<title>
<narrative>A title</narrative>
</title>
<description>
<narrative>A description</narrative>
</description>
<participating-org ref="AA-AAA-123456789" role="1"/>
<activity-status code="2"/>
<activity-date iso-date="2011-10-01" type="1"/>
<recipient-country code="AF" percentage="40"/>
<recipient-country code="XK" percentage="60"/>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2012-01-01"/>
<value value-date="2012-01-01">10</value>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2012-03-03"/>
<value value-date="2012-03-03">20</value>
</transaction>
</iati-activity>
<iati-activity>
<iati-identifier>AA-AAA-123456789-ABC124</iati-identifier>
<reporting-org ref="AA-AAA-123456789" type="40">
<narrative>Organisation name</narrative>
</reporting-org>
<title>
<narrative>Another title</narrative>
</title>
<description>
<narrative>Another description</narrative>
</description>
<participating-org ref="AA-AAA-123456789" role="1"/>
<activity-status code="3"/>
<activity-date iso-date="2016-01-01" type="2"/>
<recipient-country code="AG" percentage="30"/>
<recipient-country code="XK" percentage="70"/>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2013-04-04"/>
<value value-date="2013-04-04">30</value>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2013-05-05"/>
<value value-date="2013-05-05">40</value>
</transaction>
</iati-activity>
</iati-activities>
117 changes: 58 additions & 59 deletions examples/iati_multilang/expected.xml
Original file line number Diff line number Diff line change
@@ -1,60 +1,59 @@
<?xml version='1.0' encoding='utf-8'?>
<iati-activities>
<!--XML generated by flatten-tool-->
<iati-activity>
<iati-identifier>AA-AAA-123456789-ABC123</iati-identifier>
<reporting-org ref="AA-AAA-123456789" type="40">
<narrative>Organisation name</narrative>
</reporting-org>
<title>
<narrative xml:lang="en">A title, with comma</narrative>
<narrative xml:lang="fr">Un titre</narrative>
</title>
<description>
<narrative>A description</narrative>
</description>
<participating-org ref="AA-AAA-123456789" role="1"/>
<activity-status code="2"/>
<activity-date iso-date="2011-10-01" type="1"/>
<recipient-country code="AF" percentage="40"/>
<recipient-country code="XK" percentage="60"/>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2012-01-01"/>
<value value-date="2012-01-01">10</value>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2012-03-03"/>
<value value-date="2012-03-03">20</value>
</transaction>
</iati-activity>
<iati-activity>
<iati-identifier>AA-AAA-123456789-ABC124</iati-identifier>
<reporting-org ref="AA-AAA-123456789" type="40">
<narrative>Organisation name</narrative>
</reporting-org>
<title>
<narrative xml:lang="en">Another title; with semicolon</narrative>
<narrative xml:lang="fr">Un autre titre</narrative>
</title>
<description>
<narrative>Another description</narrative>
</description>
<participating-org ref="AA-AAA-123456789" role="1"/>
<activity-status code="3"/>
<activity-date iso-date="2016-01-01" type="2"/>
<recipient-country code="AG" percentage="30"/>
<recipient-country code="XK" percentage="70"/>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2013-04-04"/>
<value value-date="2013-04-04">30</value>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2013-05-05"/>
<value value-date="2013-05-05">40</value>
</transaction>
</iati-activity>
</iati-activities>
<iati-activities><!--XML generated by flatten-tool-->
<iati-activity>
<iati-identifier>AA-AAA-123456789-ABC123</iati-identifier>
<reporting-org ref="AA-AAA-123456789" type="40">
<narrative>Organisation name</narrative>
</reporting-org>
<title>
<narrative xml:lang="en">A title, with comma</narrative>
<narrative xml:lang="fr">Un titre</narrative>
</title>
<description>
<narrative>A description</narrative>
</description>
<participating-org ref="AA-AAA-123456789" role="1"/>
<activity-status code="2"/>
<activity-date iso-date="2011-10-01" type="1"/>
<recipient-country code="AF" percentage="40"/>
<recipient-country code="XK" percentage="60"/>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2012-01-01"/>
<value value-date="2012-01-01">10</value>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2012-03-03"/>
<value value-date="2012-03-03">20</value>
</transaction>
</iati-activity>
<iati-activity>
<iati-identifier>AA-AAA-123456789-ABC124</iati-identifier>
<reporting-org ref="AA-AAA-123456789" type="40">
<narrative>Organisation name</narrative>
</reporting-org>
<title>
<narrative xml:lang="en">Another title; with semicolon</narrative>
<narrative xml:lang="fr">Un autre titre</narrative>
</title>
<description>
<narrative>Another description</narrative>
</description>
<participating-org ref="AA-AAA-123456789" role="1"/>
<activity-status code="3"/>
<activity-date iso-date="2016-01-01" type="2"/>
<recipient-country code="AG" percentage="30"/>
<recipient-country code="XK" percentage="70"/>
<transaction>
<transaction-type code="2"/>
<transaction-date iso-date="2013-04-04"/>
<value value-date="2013-04-04">30</value>
</transaction>
<transaction>
<transaction-type code="3"/>
<transaction-date iso-date="2013-05-05"/>
<value value-date="2013-05-05">40</value>
</transaction>
</iati-activity>
</iati-activities>
Loading