Skip to content

Commit 732e487

Browse files
author
jgaff
committed
Forge current_query() and tests
Improve testing coverage in Forge. Also add Forge.current_query() to allow user to view in-progress query without searching. Update tutorial to match. A variety of small Forge improvements, including autometically discarding field:value pairs if field or value is empty.
1 parent 66091b3 commit 732e487

4 files changed

Lines changed: 277 additions & 59 deletions

File tree

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ Untitled*.ipynb
1717
prototypes/forge_sandbox.ipynb
1818

1919
travis.tar
20+
.coverage
21+

‎docs/tutorials/4 - General Helper Functions.ipynb‎

Lines changed: 105 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,73 @@
2222
"cell_type": "markdown",
2323
"metadata": {},
2424
"source": [
25-
"# Generally Useful Options"
25+
"# Generally Useful Help"
26+
]
27+
},
28+
{
29+
"cell_type": "markdown",
30+
"metadata": {},
31+
"source": [
32+
"### current_query\n",
33+
"You can see the query you're currently building with `current_query()`."
34+
]
35+
},
36+
{
37+
"cell_type": "code",
38+
"execution_count": 3,
39+
"metadata": {},
40+
"outputs": [
41+
{
42+
"data": {
43+
"text/plain": [
44+
"'(mdf.source_name:oqmd)'"
45+
]
46+
},
47+
"execution_count": 3,
48+
"metadata": {},
49+
"output_type": "execute_result"
50+
}
51+
],
52+
"source": [
53+
"mdf.match_field(\"mdf.source_name\", \"oqmd\")\n",
54+
"mdf.current_query()"
55+
]
56+
},
57+
{
58+
"cell_type": "markdown",
59+
"metadata": {},
60+
"source": [
61+
"### reset_query\n",
62+
"If you have a query in memory that you don't want, you can use `reset_query()` to start a new query. This method will clear the current query entirely."
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": 4,
68+
"metadata": {},
69+
"outputs": [],
70+
"source": [
71+
"mdf.reset_query()"
72+
]
73+
},
74+
{
75+
"cell_type": "code",
76+
"execution_count": 5,
77+
"metadata": {},
78+
"outputs": [
79+
{
80+
"data": {
81+
"text/plain": [
82+
"''"
83+
]
84+
},
85+
"execution_count": 5,
86+
"metadata": {},
87+
"output_type": "execute_result"
88+
}
89+
],
90+
"source": [
91+
"mdf.current_query()"
2692
]
2793
},
2894
{
@@ -35,7 +101,7 @@
35101
},
36102
{
37103
"cell_type": "code",
38-
"execution_count": 3,
104+
"execution_count": 6,
39105
"metadata": {},
40106
"outputs": [],
41107
"source": [
@@ -52,7 +118,7 @@
52118
},
53119
{
54120
"cell_type": "code",
55-
"execution_count": 4,
121+
"execution_count": 7,
56122
"metadata": {},
57123
"outputs": [
58124
{
@@ -61,23 +127,23 @@
61127
"{'mdf': {'collection': 'AMCS',\n",
62128
" 'composition': 'Al4',\n",
63129
" 'elements': ['Al'],\n",
64-
" 'ingest_date': '2017-08-04T19:07:56.890584Z',\n",
130+
" 'ingest_date': '2017-08-04T19:02:11.268680Z',\n",
65131
" 'links': {'cif': {'http_host': 'http://rruff.geo.arizona.edu',\n",
66-
" 'path': '/AMS/xtal_data/CIFfiles/19141.cif'},\n",
132+
" 'path': '/AMS/xtal_data/CIFfiles/13121.cif'},\n",
67133
" 'dif': {'http_host': 'http://rruff.geo.arizona.edu',\n",
68-
" 'path': '/AMS/xtal_data/DIFfiles/19141.txt'},\n",
69-
" 'landing_page': 'http://rruff.geo.arizona.edu/AMS/minerals/Aluminum#18135',\n",
134+
" 'path': '/AMS/xtal_data/DIFfiles/13121.txt'},\n",
135+
" 'landing_page': 'http://rruff.geo.arizona.edu/AMS/minerals/Aluminum',\n",
70136
" 'parent_id': '5984c125f2c0043771d1507c'},\n",
71-
" 'mdf_id': '5984c60cf2c0043771d19753',\n",
137+
" 'mdf_id': '5984c4b3f2c0043771d180a2',\n",
72138
" 'metadata_version': '0.3.2',\n",
73139
" 'resource_type': 'record',\n",
74-
" 'scroll_id': 18135,\n",
140+
" 'scroll_id': 12326,\n",
75141
" 'source_name': 'amcs',\n",
76142
" 'tags': ['Aluminum', 'cif', 'dif'],\n",
77143
" 'title': 'AMCS - Aluminum'}}"
78144
]
79145
},
80-
"execution_count": 4,
146+
"execution_count": 7,
81147
"metadata": {},
82148
"output_type": "execute_result"
83149
}
@@ -88,7 +154,7 @@
88154
},
89155
{
90156
"cell_type": "code",
91-
"execution_count": 5,
157+
"execution_count": 8,
92158
"metadata": {},
93159
"outputs": [
94160
{
@@ -98,10 +164,10 @@
98164
" 'limit': 10,\n",
99165
" 'offset': 0,\n",
100166
" 'q': '( NOT mdf.source_name:sluschi AND mdf.elements:Al AND NOT mdf.source_name:oqmd)'},\n",
101-
" 'total_query_matches': 18177}"
167+
" 'total_query_matches': 18170}"
102168
]
103169
},
104-
"execution_count": 5,
170+
"execution_count": 8,
105171
"metadata": {},
106172
"output_type": "execute_result"
107173
}
@@ -120,16 +186,16 @@
120186
},
121187
{
122188
"cell_type": "code",
123-
"execution_count": 6,
189+
"execution_count": 9,
124190
"metadata": {},
125191
"outputs": [
126192
{
127193
"data": {
128194
"text/plain": [
129-
"<mdf_forge.forge.Forge at 0x7f27a81b61d0>"
195+
"<mdf_forge.forge.Forge at 0x7fc52fd1d6d8>"
130196
]
131197
},
132-
"execution_count": 6,
198+
"execution_count": 9,
133199
"metadata": {},
134200
"output_type": "execute_result"
135201
}
@@ -140,7 +206,7 @@
140206
},
141207
{
142208
"cell_type": "code",
143-
"execution_count": 7,
209+
"execution_count": 10,
144210
"metadata": {},
145211
"outputs": [
146212
{
@@ -149,7 +215,7 @@
149215
"'(mdf.source_name:nist_xps_db)'"
150216
]
151217
},
152-
"execution_count": 7,
218+
"execution_count": 10,
153219
"metadata": {},
154220
"output_type": "execute_result"
155221
}
@@ -161,7 +227,7 @@
161227
},
162228
{
163229
"cell_type": "code",
164-
"execution_count": 8,
230+
"execution_count": 11,
165231
"metadata": {},
166232
"outputs": [
167233
{
@@ -170,7 +236,7 @@
170236
"'(mdf.source_name:nist_xps_db)'"
171237
]
172238
},
173-
"execution_count": 8,
239+
"execution_count": 11,
174240
"metadata": {},
175241
"output_type": "execute_result"
176242
}
@@ -190,7 +256,7 @@
190256
},
191257
{
192258
"cell_type": "code",
193-
"execution_count": 9,
259+
"execution_count": 12,
194260
"metadata": {},
195261
"outputs": [
196262
{
@@ -215,7 +281,7 @@
215281
" 'xafs_sl': 'object'}"
216282
]
217283
},
218-
"execution_count": 9,
284+
"execution_count": 12,
219285
"metadata": {},
220286
"output_type": "execute_result"
221287
}
@@ -233,9 +299,9 @@
233299
},
234300
{
235301
"cell_type": "code",
236-
"execution_count": 10,
302+
"execution_count": 13,
237303
"metadata": {
238-
"scrolled": false
304+
"scrolled": true
239305
},
240306
"outputs": [
241307
{
@@ -456,7 +522,7 @@
456522
" 'mdf.year': 'long'}"
457523
]
458524
},
459-
"execution_count": 10,
525+
"execution_count": 13,
460526
"metadata": {},
461527
"output_type": "execute_result"
462528
}
@@ -482,7 +548,7 @@
482548
},
483549
{
484550
"cell_type": "code",
485-
"execution_count": 11,
551+
"execution_count": 14,
486552
"metadata": {},
487553
"outputs": [],
488554
"source": [
@@ -491,8 +557,10 @@
491557
},
492558
{
493559
"cell_type": "code",
494-
"execution_count": 12,
495-
"metadata": {},
560+
"execution_count": 15,
561+
"metadata": {
562+
"scrolled": true
563+
},
496564
"outputs": [
497565
{
498566
"data": {
@@ -535,7 +603,7 @@
535603
" 'year': 2016}}"
536604
]
537605
},
538-
"execution_count": 12,
606+
"execution_count": 15,
539607
"metadata": {},
540608
"output_type": "execute_result"
541609
}
@@ -554,8 +622,10 @@
554622
},
555623
{
556624
"cell_type": "code",
557-
"execution_count": 13,
558-
"metadata": {},
625+
"execution_count": 16,
626+
"metadata": {
627+
"scrolled": true
628+
},
559629
"outputs": [
560630
{
561631
"data": {
@@ -598,7 +668,7 @@
598668
" 'year': 2015}}"
599669
]
600670
},
601-
"execution_count": 13,
671+
"execution_count": 16,
602672
"metadata": {},
603673
"output_type": "execute_result"
604674
}
@@ -632,7 +702,7 @@
632702
},
633703
{
634704
"cell_type": "code",
635-
"execution_count": 14,
705+
"execution_count": 17,
636706
"metadata": {},
637707
"outputs": [
638708
{
@@ -658,14 +728,14 @@
658728
},
659729
{
660730
"cell_type": "code",
661-
"execution_count": 15,
731+
"execution_count": 18,
662732
"metadata": {},
663733
"outputs": [
664734
{
665735
"name": "stderr",
666736
"output_type": "stream",
667737
"text": [
668-
"100%|██████████| 23269/23269 [01:00<00:00, 375.08it/s]"
738+
"100%|██████████| 23269/23269 [01:00<00:00, 356.91it/s]"
669739
]
670740
},
671741
{

0 commit comments

Comments
 (0)