Skip to content

Commit b3a0055

Browse files
committed
📚 more documentation
1 parent e4d8896 commit b3a0055

File tree

5 files changed

+165
-8
lines changed

5 files changed

+165
-8
lines changed

.moban.d/README.rst

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ What's new?
4141
| 2 | 3 |
4242
+---+---+
4343
>>> highspeedrail = pe.Sheet()
44-
>>> sheet.json = """
44+
>>> highspeedrail.json = """
4545
... [{"year": 1903, "country": "Germany", "speed": "206.7km/h"},
4646
... {"year": 1964, "country": "Japan", "speed": "210km/h"},
4747
... {"year": 2008, "country": "China", "speed": "350km/h"}]
4848
... """
49-
>>> sheet.name = 'High Speed Train Speed Break Through (Source: Wikipedia)'
50-
>>> sheet
49+
>>> highspeedrail.name = 'High Speed Train Speed Break Through (Source: Wikipedia)'
50+
>>> highspeedrail
5151
High Speed Train Speed Break Through (Source: Wikipedia):
5252
+---------+-----------+------+
5353
| country | speed | year |
@@ -58,6 +58,42 @@ What's new?
5858
+---------+-----------+------+
5959
| China | 350km/h | 2008 |
6060
+---------+-----------+------+
61+
>>> henley_on_thames_facts = pe.Sheet()
62+
>>> henley_on_thames_facts.json = """
63+
... {"area": "5.58 square meters",
64+
... "population": "11,619",
65+
... "civial parish": "Henley-on-Thames",
66+
... "latitude": "51.536",
67+
... "longitude": "-0.898"
68+
... }"""
69+
>>> henley_on_thames_facts
70+
pyexcel sheet:
71+
+--------------------+------------------+----------+-----------+------------+
72+
| area | civial parish | latitude | longitude | population |
73+
+--------------------+------------------+----------+-----------+------------+
74+
| 5.58 square meters | Henley-on-Thames | 51.536 | -0.898 | 11,619 |
75+
+--------------------+------------------+----------+-----------+------------+
76+
>>> ccs_insight = pe.Sheet()
77+
>>> ccs_insight.name = "Worldwide Mobile Phone Shipments (Billions), 2017-2021"
78+
>>> ccs_insight.json = """
79+
... {"year": ["2017", "2018", "2019", "2020", "2021"],
80+
... "smart phones": [1.53, 1.64, 1.74, 1.82, 1.90],
81+
... "feature phones": [0.46, 0.38, 0.30, 0.23, 0.17]}"""
82+
>>> ccs_insight
83+
pyexcel sheet:
84+
+----------------+--------------+------+
85+
| feature phones | smart phones | year |
86+
+----------------+--------------+------+
87+
| 0.46 | 1.53 | 2017 |
88+
+----------------+--------------+------+
89+
| 0.38 | 1.64 | 2018 |
90+
+----------------+--------------+------+
91+
| 0.3 | 1.74 | 2019 |
92+
+----------------+--------------+------+
93+
| 0.23 | 1.82 | 2020 |
94+
+----------------+--------------+------+
95+
| 0.17 | 1.9 | 2021 |
96+
+----------------+--------------+------+
6197
6298
Here is a variant of json:
6399

@@ -79,6 +115,43 @@ Here is a variant of json:
79115
+---------+-----------+------+
80116
| China | 350km/h | 2008 |
81117
+---------+-----------+------+
118+
>>> henley_on_thames_facts2 = pe.Sheet()
119+
>>> henley_on_thames_facts2.ndjson = """
120+
... {"area": "5.58 square meters"}
121+
... {"population": "11,619"}
122+
... {"civial parish": "Henley-on-Thames"}
123+
... {"latitude": "51.536"}
124+
... {"longitude": "-0.898"}
125+
... """.strip()
126+
>>> henley_on_thames_facts2
127+
pyexcel sheet:
128+
+---------------+--------------------+
129+
| area | 5.58 square meters |
130+
+---------------+--------------------+
131+
| population | 11,619 |
132+
+---------------+--------------------+
133+
| civial parish | Henley-on-Thames |
134+
+---------------+--------------------+
135+
| latitude | 51.536 |
136+
+---------------+--------------------+
137+
| longitude | -0.898 |
138+
+---------------+--------------------+
139+
>>> ccs_insight2 = pe.Sheet()
140+
>>> ccs_insight2.name = "Worldwide Mobile Phone Shipments (Billions), 2017-2021"
141+
>>> ccs_insight2.ndjson = """
142+
... {"year": ["2017", "2018", "2019", "2020", "2021"]}
143+
... {"smart phones": [1.53, 1.64, 1.74, 1.82, 1.90]}
144+
... {"feature phones": [0.46, 0.38, 0.30, 0.23, 0.17]}
145+
... """.strip()
146+
>>> ccs_insight2
147+
pyexcel sheet:
148+
+----------------+------+------+------+------+------+
149+
| year | 2017 | 2018 | 2019 | 2020 | 2021 |
150+
+----------------+------+------+------+------+------+
151+
| smart phones | 1.53 | 1.64 | 1.74 | 1.82 | 1.9 |
152+
+----------------+------+------+------+------+------+
153+
| feature phones | 0.46 | 0.38 | 0.3 | 0.23 | 0.17 |
154+
+----------------+------+------+------+------+------+
82155

83156

84157
Simple

README.rst

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ What's new?
5050
| 2 | 3 |
5151
+---+---+
5252
>>> highspeedrail = pe.Sheet()
53-
>>> sheet.json = """
53+
>>> highspeedrail.json = """
5454
... [{"year": 1903, "country": "Germany", "speed": "206.7km/h"},
5555
... {"year": 1964, "country": "Japan", "speed": "210km/h"},
5656
... {"year": 2008, "country": "China", "speed": "350km/h"}]
5757
... """
58-
>>> sheet.name = 'High Speed Train Speed Break Through (Source: Wikipedia)'
59-
>>> sheet
58+
>>> highspeedrail.name = 'High Speed Train Speed Break Through (Source: Wikipedia)'
59+
>>> highspeedrail
6060
High Speed Train Speed Break Through (Source: Wikipedia):
6161
+---------+-----------+------+
6262
| country | speed | year |
@@ -67,6 +67,42 @@ What's new?
6767
+---------+-----------+------+
6868
| China | 350km/h | 2008 |
6969
+---------+-----------+------+
70+
>>> henley_on_thames_facts = pe.Sheet()
71+
>>> henley_on_thames_facts.json = """
72+
... {"area": "5.58 square meters",
73+
... "population": "11,619",
74+
... "civial parish": "Henley-on-Thames",
75+
... "latitude": "51.536",
76+
... "longitude": "-0.898"
77+
... }"""
78+
>>> henley_on_thames_facts
79+
pyexcel sheet:
80+
+--------------------+------------------+----------+-----------+------------+
81+
| area | civial parish | latitude | longitude | population |
82+
+--------------------+------------------+----------+-----------+------------+
83+
| 5.58 square meters | Henley-on-Thames | 51.536 | -0.898 | 11,619 |
84+
+--------------------+------------------+----------+-----------+------------+
85+
>>> ccs_insight = pe.Sheet()
86+
>>> ccs_insight.name = "Worldwide Mobile Phone Shipments (Billions), 2017-2021"
87+
>>> ccs_insight.json = """
88+
... {"year": ["2017", "2018", "2019", "2020", "2021"],
89+
... "smart phones": [1.53, 1.64, 1.74, 1.82, 1.90],
90+
... "feature phones": [0.46, 0.38, 0.30, 0.23, 0.17]}"""
91+
>>> ccs_insight
92+
pyexcel sheet:
93+
+----------------+--------------+------+
94+
| feature phones | smart phones | year |
95+
+----------------+--------------+------+
96+
| 0.46 | 1.53 | 2017 |
97+
+----------------+--------------+------+
98+
| 0.38 | 1.64 | 2018 |
99+
+----------------+--------------+------+
100+
| 0.3 | 1.74 | 2019 |
101+
+----------------+--------------+------+
102+
| 0.23 | 1.82 | 2020 |
103+
+----------------+--------------+------+
104+
| 0.17 | 1.9 | 2021 |
105+
+----------------+--------------+------+
70106
71107
Here is a variant of json:
72108

@@ -88,6 +124,43 @@ Here is a variant of json:
88124
+---------+-----------+------+
89125
| China | 350km/h | 2008 |
90126
+---------+-----------+------+
127+
>>> henley_on_thames_facts2 = pe.Sheet()
128+
>>> henley_on_thames_facts2.ndjson = """
129+
... {"area": "5.58 square meters"}
130+
... {"population": "11,619"}
131+
... {"civial parish": "Henley-on-Thames"}
132+
... {"latitude": "51.536"}
133+
... {"longitude": "-0.898"}
134+
... """.strip()
135+
>>> henley_on_thames_facts2
136+
pyexcel sheet:
137+
+---------------+--------------------+
138+
| area | 5.58 square meters |
139+
+---------------+--------------------+
140+
| population | 11,619 |
141+
+---------------+--------------------+
142+
| civial parish | Henley-on-Thames |
143+
+---------------+--------------------+
144+
| latitude | 51.536 |
145+
+---------------+--------------------+
146+
| longitude | -0.898 |
147+
+---------------+--------------------+
148+
>>> ccs_insight2 = pe.Sheet()
149+
>>> ccs_insight2.name = "Worldwide Mobile Phone Shipments (Billions), 2017-2021"
150+
>>> ccs_insight2.ndjson = """
151+
... {"year": ["2017", "2018", "2019", "2020", "2021"]}
152+
... {"smart phones": [1.53, 1.64, 1.74, 1.82, 1.90]}
153+
... {"feature phones": [0.46, 0.38, 0.30, 0.23, 0.17]}
154+
... """.strip()
155+
>>> ccs_insight2
156+
pyexcel sheet:
157+
+----------------+------+------+------+------+------+
158+
| year | 2017 | 2018 | 2019 | 2020 | 2021 |
159+
+----------------+------+------+------+------+------+
160+
| smart phones | 1.53 | 1.64 | 1.74 | 1.82 | 1.9 |
161+
+----------------+------+------+------+------+------+
162+
| feature phones | 0.46 | 0.38 | 0.3 | 0.23 | 0.17 |
163+
+----------------+------+------+------+------+------+
91164

92165

93166
Simple

pyexcel_text/ndjsonp.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,12 @@ def json_loads(file_stream):
8484
"""
8585
Simple load each line as json
8686
"""
87-
for raw_row in file_stream:
88-
yield json.loads(raw_row)
87+
try:
88+
for raw_row in file_stream:
89+
yield json.loads(raw_row)
90+
except ValueError:
91+
raise ValueError("There has been an json decode error."
92+
"Current version is not error tolerant")
8993

9094

9195
def detect_format(content_generator):

tests/fixtures/bad.ndjson

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
...

tests/test_ndjsonp.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ def test_unknown_format(self):
9393
self.content = self.parser.parse_file(get_file("unknown.ndjson"),
9494
sheet_name=sheet_name)
9595

96+
@raises(ValueError)
97+
def test_bad_json_format(self):
98+
sheet_name = 'test'
99+
self.content = self.parser.parse_file(get_file("bad.ndjson"),
100+
sheet_name=sheet_name)
101+
96102
def _verify(self, expected):
97103
for key in self.content:
98104
self.content[key] = list(self.content[key])

0 commit comments

Comments
 (0)