Repository: saulpw/visidata

Issue:
YAML fails reading files with tuples
Example file:

```
foo: !!python/tuple
- 1
- 2
- 3
```

Error:

```
ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:python/tuple'·
```


Discussion:
This is a problem for the `yaml` library itself.  If you can get that library to parse tuples itself, then the problem can be fixed in VisiData.
If I can solve the problem by calling `yaml.add_constructor` rather than making any modifications to the `yaml` library, would you merge that? 
Of course, that's how it should be. Maybe we could add a comprehensive .yml file to test against too.

Resolving patch:
diff --git a/visidata/loaders/yaml.py b/visidata/loaders/yaml.py
--- a/visidata/loaders/yaml.py
+++ b/visidata/loaders/yaml.py
@@ -12,8 +12,18 @@ def open_yml(vd, p):
 class YamlSheet(JsonSheet):
     def iterload(self):
         yaml = vd.importExternal('yaml', 'PyYAML')
+
+        class PrettySafeLoader(yaml.SafeLoader):
+            def construct_python_tuple(self, node):
+                return tuple(self.construct_sequence(node))
+
+        PrettySafeLoader.add_constructor(
+            u'tag:yaml.org,2002:python/tuple',
+            PrettySafeLoader.construct_python_tuple
+        )
+
         with self.source.open_text() as fp:
-            documents = yaml.safe_load_all(fp)
+            documents = yaml.load_all(fp, PrettySafeLoader)
 
             self.columns = []
             self._knownKeys.clear()


Test patch:
diff --git a/tests/golden/load-yaml.tsv b/tests/golden/load-yaml.tsv
--- a/tests/golden/load-yaml.tsv
+++ b/tests/golden/load-yaml.tsv
@@ -1,52 +1,53 @@
-customer	date	item	paid	quantity	sku	unit
-Robert Armstrong	7/3/2018 1:47p	BFF Oh My Gravy! Beef & Salmon 2.8oz	$51.8	4	FOOD213	$12.95
-Kyle Kennedy	7/3/2018 3:32p	Food, Adult Cat - 3.5 oz	$4.22	1	FOOD121	$4.22
-Douglas "Dougie" Powers	7/5/2018 4:15p	Food, Adult Cat 3.5 oz	$4.22	1	FOOD121	$4.22
-桜 高橋 (Sakura Takahashi)	7/6/2018 12:15p	Food, Senior Wet Cat - 3 oz	157¥	12	FOOD122	$1.29
-David Attenborough	7/10/2018 10:28a	Food, Salamander	$1.5	30	NSCT201	$.05
-Susan Ashworth	7/10/2018 5:23p	Cat, Korat (Felis catus)	$720.42	1	CAT060	$720.42
-Susan Ashworth	7/10/2018 5:23p	Food, Kitten 3kg	$14.94	1	FOOD130	$14.94
-Wil Wheaton	7/13/2018 10:26a	Monster, Rust (Monstrus gygaxus)	$39.95	1	NSCT523	$39.95
-Robert Armstrong	7/13/2018 3:49p	BFF Oh My Gravy! Chicken & Shrimp 2.8oz	$51.8	4	FOOD216	$12.95
-Robert Armstrong	7/17/2018 9:01a	BFF Oh My Gravy! Duck & Tuna 2.8oz	$51.8	4	FOOD217	$12.95
-Helen Halestorm	7/17/2018 11:30a	Rabbit (Oryctolagus cuniculus)	$65.88	2	LAGO342	$32.94
-桜 高橋 (Sakura Takahashi)	7/18/2018 12:16p	Food, Senior Wet Cat - 3 oz	157¥	6	FOOD122	$1.29
-Rubeus Hagrid	7/19/2018 10:28a	Food, Dog - 5kg	$224.75	5	FOOD170	$44.95
-Jon Arbuckle	7/20/2018 2:13p	Food, Premium Wet Cat - 3.5 oz	$197.5	50	FOOD167	$3.95
-Robert Armstrong	7/23/2018 1:41p	BFF Oh My Gravy! Lamb & Tuna 2.8oz	$51.8	4	FOOD215	$12.95
-Douglas "Dougie" Powers	7/23/2018 4:23p	Laser Pointer	$16.12	1	TOY235	$16.12
-桜 高橋 (Sakura Takahashi)	7/24/2018 12:16p	Food, Senior Wet Cat - 3 oz	157¥	3	FOOD122	$1.29
-Douglas "Dougie" Powers	7/26/2018 4:39p	Food, Shark - 10 kg	$15.7	1	FOOD420	$15.70
-桜 高橋 (Sakura Takahashi)	7/27/2018 12:16p	Food, Senior Wet Cat - 3 oz	157¥	3	FOOD122	$1.29
-桜 高橋 (Sakura Takahashi)	7/30/2018 12:17p	Food, Senior Wet Cat - 3 oz	157¥	1	RETURN	$1.29
-Rubeus Hagrid	7/31/2018 5:42p	Food, Dragon - 50kg	$3602.1	5	CAT060	$720.42
-David Attenborough	8/1/2018 2:44p	Food, Rhinocerous - 50kg	$22.88	4	FOOD360	$5.72
-Susan Ashworth	8/2/2018 5:12p	Cat, Maine Coon (Felix catus)	$1309.68	1	CAT110	$1,309.68
-Susan Ashworth	8/2/2018 5:12p	Food, Kitten 3kg	$44.82	3	FOOD130	$14.94
-Robert Armstrong	8/6/2018 10:21a	BFF Oh My Gravy! Beef & Chicken 2.8oz	$51.8	4	FOOD212	$12.95
-Juan Johnson	8/7/2018 4:12p	Kingsnake, California (Lampropeltis getula)	$89.95	1	REPT082	$89.95
-Juan Johnson	8/7/2018 4:12p	Mouse, Pinky (Mus musculus)	$1.49	1	RDNT443	$1.49
-Robert Armstrong	8/10/2018 4:31p	BFF Oh My Gravy! Chicken & Turkey 2.8oz	$51.8	4	FOOD211	$12.95
-Monica Johnson	8/13/2018 2:07p	Mouse, Pinky (Mus musculus)	$1.49	1	RDNT443	$1.49
-María Fernández	8/13/2018 2:08p	Forti Diet Prohealth Mouse/Rat 3lbs	$4.0	2	FOOD146	$2.00
-Mr. Praline	8/15/2018 11:57a	Parrot, Norwegian Blue (Mopsitta tanta)	-$2300.0	1	RETURN	$2300.00
-Kyle Kennedy	8/15/2018 3:48p	Food, Adult Cat - 3.5 oz	$8.44	2	FOOD121	$4.22
-Helen Halestorm	8/16/2018 11:50a	Rabbit (Oryctolagus cuniculus)	$0.0	6	RETURN	$0
-Kyle Kennedy	8/16/2018 4:00p	Dog, Golden Retriever (Canis lupus familiaris)	$2495.99	1	DOG010	$2,495.99
-Michael Smith	8/16/2018 5:15p	Parakeet, Blue (Melopsittacus undulatus)	$31.85	1	BIRD160	29.95
-Rubeus Hagrid	8/17/2018 9:26a	Food, Spider	$0.25	5	NSCT201	$.05
-Kyle Kennedy	8/20/2018 9:36a	Dog, Golden Retriever (Canis lupus familiaris)	-$1247.99	1	RETURN	$1,247.99
-מרוסיה ניסנהולץ אבולעפיה	8/20/2018 1:47p	Goat, American Pygmy (Capra hircus)	$160.51	1	GOAT224	₪499
-Monica Johnson	8/20/2018 3:31p	Crickets, Adult Live (Gryllus assimilis)	$1.5	30	NSCT201	$.05
-David Attenborough	8/20/2018 5:12p	Food, Pangolin	$5.10	30	NSCT084	$.17
-Robert Armstrong	8/21/2018 12:13p	BFF Oh My Gravy! Duck & Salmon 2.8oz	$51.8	4	FOOD214	$12.95
-David Attenborough	8/22/2018 9:38a	Food, Quoll	$29.95	1	BIRD160	29.95
-Jon Arbuckle	8/22/2018 2:13p	Food, Adult Dog - 5kg	$44.95	1	FOOD170	$44.95
-מרוסיה ניסנהולץ	8/22/2018 5:49p	Fire Extinguisher, kitchen-rated	$61.70	1	SFTY052	$61.70
-Robert Armstrong	8/24/2018 11:42a	BFF Oh My Gravy! Chicken & Salmon 2.8oz	$51.8	4	FOOD218	$12.95
-Monica Johnson	8/27/2018 3:05p	Mealworms, Large (Tenebrio molitor) 100ct	$1.99	1	NSCT443	$1.99
-Susan Ashworth	8/28/2018 5:32p	Cat, Scottish Fold (Felis catus)	$1964.53	1	CAT020	$1,964.53
-Susan Ashworth	8/28/2018 5:32p	Food, Kitten 3kg	$29.88	2	FOOD130	$14.94
-Robert Armstrong	8/29/2018 10:07a	BFF Oh My Gravy! Chicken & Pumpkin 2.8oz	$51.8	4	FOOD219	$12.95
-Robert Armstrong	8/31/2018 12:00a	BFF Oh My Gravy! Chicken & Pumpkin 2.8oz	$1864.8	144	FOOD219	$12.95
-Juan Johnson	8/31/2018 5:57p	Lizard, Spinytail (Uromastyx ornatus)	$99.95	1	REPT217	$99.95
+customer	date	foo	item	paid	quantity	sku	unit
+Robert Armstrong	7/3/2018 1:47p		BFF Oh My Gravy! Beef & Salmon 2.8oz	$51.8	4	FOOD213	$12.95
+Kyle Kennedy	7/3/2018 3:32p		Food, Adult Cat - 3.5 oz	$4.22	1	FOOD121	$4.22
+Douglas "Dougie" Powers	7/5/2018 4:15p		Food, Adult Cat 3.5 oz	$4.22	1	FOOD121	$4.22
+桜 高橋 (Sakura Takahashi)	7/6/2018 12:15p		Food, Senior Wet Cat - 3 oz	157¥	12	FOOD122	$1.29
+David Attenborough	7/10/2018 10:28a		Food, Salamander	$1.5	30	NSCT201	$.05
+Susan Ashworth	7/10/2018 5:23p		Cat, Korat (Felis catus)	$720.42	1	CAT060	$720.42
+Susan Ashworth	7/10/2018 5:23p		Food, Kitten 3kg	$14.94	1	FOOD130	$14.94
+Wil Wheaton	7/13/2018 10:26a		Monster, Rust (Monstrus gygaxus)	$39.95	1	NSCT523	$39.95
+Robert Armstrong	7/13/2018 3:49p		BFF Oh My Gravy! Chicken & Shrimp 2.8oz	$51.8	4	FOOD216	$12.95
+Robert Armstrong	7/17/2018 9:01a		BFF Oh My Gravy! Duck & Tuna 2.8oz	$51.8	4	FOOD217	$12.95
+Helen Halestorm	7/17/2018 11:30a		Rabbit (Oryctolagus cuniculus)	$65.88	2	LAGO342	$32.94
+桜 高橋 (Sakura Takahashi)	7/18/2018 12:16p		Food, Senior Wet Cat - 3 oz	157¥	6	FOOD122	$1.29
+Rubeus Hagrid	7/19/2018 10:28a		Food, Dog - 5kg	$224.75	5	FOOD170	$44.95
+Jon Arbuckle	7/20/2018 2:13p		Food, Premium Wet Cat - 3.5 oz	$197.5	50	FOOD167	$3.95
+Robert Armstrong	7/23/2018 1:41p		BFF Oh My Gravy! Lamb & Tuna 2.8oz	$51.8	4	FOOD215	$12.95
+Douglas "Dougie" Powers	7/23/2018 4:23p		Laser Pointer	$16.12	1	TOY235	$16.12
+桜 高橋 (Sakura Takahashi)	7/24/2018 12:16p		Food, Senior Wet Cat - 3 oz	157¥	3	FOOD122	$1.29
+Douglas "Dougie" Powers	7/26/2018 4:39p		Food, Shark - 10 kg	$15.7	1	FOOD420	$15.70
+桜 高橋 (Sakura Takahashi)	7/27/2018 12:16p		Food, Senior Wet Cat - 3 oz	157¥	3	FOOD122	$1.29
+桜 高橋 (Sakura Takahashi)	7/30/2018 12:17p		Food, Senior Wet Cat - 3 oz	157¥	1	RETURN	$1.29
+Rubeus Hagrid	7/31/2018 5:42p		Food, Dragon - 50kg	$3602.1	5	CAT060	$720.42
+David Attenborough	8/1/2018 2:44p		Food, Rhinocerous - 50kg	$22.88	4	FOOD360	$5.72
+Susan Ashworth	8/2/2018 5:12p		Cat, Maine Coon (Felix catus)	$1309.68	1	CAT110	$1,309.68
+Susan Ashworth	8/2/2018 5:12p		Food, Kitten 3kg	$44.82	3	FOOD130	$14.94
+Robert Armstrong	8/6/2018 10:21a		BFF Oh My Gravy! Beef & Chicken 2.8oz	$51.8	4	FOOD212	$12.95
+Juan Johnson	8/7/2018 4:12p		Kingsnake, California (Lampropeltis getula)	$89.95	1	REPT082	$89.95
+Juan Johnson	8/7/2018 4:12p		Mouse, Pinky (Mus musculus)	$1.49	1	RDNT443	$1.49
+Robert Armstrong	8/10/2018 4:31p		BFF Oh My Gravy! Chicken & Turkey 2.8oz	$51.8	4	FOOD211	$12.95
+Monica Johnson	8/13/2018 2:07p		Mouse, Pinky (Mus musculus)	$1.49	1	RDNT443	$1.49
+María Fernández	8/13/2018 2:08p		Forti Diet Prohealth Mouse/Rat 3lbs	$4.0	2	FOOD146	$2.00
+Mr. Praline	8/15/2018 11:57a		Parrot, Norwegian Blue (Mopsitta tanta)	-$2300.0	1	RETURN	$2300.00
+Kyle Kennedy	8/15/2018 3:48p		Food, Adult Cat - 3.5 oz	$8.44	2	FOOD121	$4.22
+Helen Halestorm	8/16/2018 11:50a		Rabbit (Oryctolagus cuniculus)	$0.0	6	RETURN	$0
+Kyle Kennedy	8/16/2018 4:00p		Dog, Golden Retriever (Canis lupus familiaris)	$2495.99	1	DOG010	$2,495.99
+Michael Smith	8/16/2018 5:15p		Parakeet, Blue (Melopsittacus undulatus)	$31.85	1	BIRD160	29.95
+Rubeus Hagrid	8/17/2018 9:26a		Food, Spider	$0.25	5	NSCT201	$.05
+Kyle Kennedy	8/20/2018 9:36a		Dog, Golden Retriever (Canis lupus familiaris)	-$1247.99	1	RETURN	$1,247.99
+מרוסיה ניסנהולץ אבולעפיה	8/20/2018 1:47p		Goat, American Pygmy (Capra hircus)	$160.51	1	GOAT224	₪499
+Monica Johnson	8/20/2018 3:31p		Crickets, Adult Live (Gryllus assimilis)	$1.5	30	NSCT201	$.05
+David Attenborough	8/20/2018 5:12p		Food, Pangolin	$5.10	30	NSCT084	$.17
+Robert Armstrong	8/21/2018 12:13p		BFF Oh My Gravy! Duck & Salmon 2.8oz	$51.8	4	FOOD214	$12.95
+David Attenborough	8/22/2018 9:38a		Food, Quoll	$29.95	1	BIRD160	29.95
+Jon Arbuckle	8/22/2018 2:13p		Food, Adult Dog - 5kg	$44.95	1	FOOD170	$44.95
+מרוסיה ניסנהולץ	8/22/2018 5:49p		Fire Extinguisher, kitchen-rated	$61.70	1	SFTY052	$61.70
+Robert Armstrong	8/24/2018 11:42a		BFF Oh My Gravy! Chicken & Salmon 2.8oz	$51.8	4	FOOD218	$12.95
+Monica Johnson	8/27/2018 3:05p		Mealworms, Large (Tenebrio molitor) 100ct	$1.99	1	NSCT443	$1.99
+Susan Ashworth	8/28/2018 5:32p		Cat, Scottish Fold (Felis catus)	$1964.53	1	CAT020	$1,964.53
+Susan Ashworth	8/28/2018 5:32p		Food, Kitten 3kg	$29.88	2	FOOD130	$14.94
+Robert Armstrong	8/29/2018 10:07a		BFF Oh My Gravy! Chicken & Pumpkin 2.8oz	$51.8	4	FOOD219	$12.95
+Robert Armstrong	8/31/2018 12:00a		BFF Oh My Gravy! Chicken & Pumpkin 2.8oz	$1864.8	144	FOOD219	$12.95
+Juan Johnson	8/31/2018 5:57p		Lizard, Spinytail (Uromastyx ornatus)	$99.95	1	REPT217	$99.95
+		[3] 1; 2; 3