@@ -98,6 +98,19 @@ def convert_type(type_string, value, timezone = pytz.timezone('UTC')):
98
98
raise ValueError ('Unrecognised type: "{}"' .format (type_string ))
99
99
100
100
101
+ def warnings_for_ignored_columns (v , extra_message ):
102
+ if isinstance (v , Cell ):
103
+ warn ('Column {} has been ignored, {}' .format (v .cell_location [3 ], extra_message ))
104
+ elif isinstance (v , dict ):
105
+ for x in v .values ():
106
+ warnings_for_ignored_columns (x , extra_message )
107
+ elif isinstance (v , TemporaryDict ):
108
+ for x in v .to_list ():
109
+ warnings_for_ignored_columns (x , extra_message )
110
+ else :
111
+ raise ValueError ()
112
+
113
+
101
114
def merge (base , mergee , debug_info = None ):
102
115
if not debug_info :
103
116
debug_info = {}
@@ -108,6 +121,9 @@ def merge(base, mergee, debug_info=None):
108
121
value = v
109
122
if key in base :
110
123
if isinstance (value , TemporaryDict ):
124
+ if not isinstance (base [key ], TemporaryDict ):
125
+ warnings_for_ignored_columns (v , 'because it treats {} as an array, but another column does not' .format (key ))
126
+ continue
111
127
for temporarydict_key , temporarydict_value in value .items ():
112
128
if temporarydict_key in base [key ]:
113
129
merge (base [key ][temporarydict_key ], temporarydict_value , debug_info )
@@ -116,9 +132,18 @@ def merge(base, mergee, debug_info=None):
116
132
base [key ][temporarydict_key ] = temporarydict_value
117
133
for temporarydict_value in value .items_no_keyfield :
118
134
base [key ].items_no_keyfield .append (temporarydict_value )
119
- elif isinstance (value , dict ) and isinstance (base [key ], dict ):
120
- merge (base [key ], value , debug_info )
135
+ elif isinstance (value , dict ):
136
+ if isinstance (base [key ], dict ):
137
+ merge (base [key ], value , debug_info )
138
+ else :
139
+ warnings_for_ignored_columns (v , 'because it treats {} as an object, but another column does not' .format (key ))
121
140
else :
141
+ if not isinstance (base [key ], Cell ):
142
+ id_info = '{} "{}"' .format (debug_info .get ('id_name' ), debug_info .get (debug_info .get ('id_name' )))
143
+ if debug_info .get ('root_id' ):
144
+ id_info = '{} "{}", ' .format (debug_info .get ('root_id' ), debug_info .get ('root_id_or_none' ))+ id_info
145
+ warnings_for_ignored_columns (v , 'because another column treats it as an array or object' .format (key ))
146
+ continue
122
147
base_value = base [key ].cell_value
123
148
if base_value != value :
124
149
id_info = '{} "{}"' .format (debug_info .get ('id_name' ), debug_info .get (debug_info .get ('id_name' )))
@@ -149,7 +174,7 @@ def convert_dict_titles(self, dicts, title_lookup=None):
149
174
150
175
"""
151
176
if self .parser :
152
- title_lookup = title_lookup or self .parser .title_lookup
177
+ title_lookup = self .parser .title_lookup
153
178
for d in dicts :
154
179
if title_lookup :
155
180
yield OrderedDict ([(title_lookup .lookup_header (k ), v ) for k ,v in d .items ()])
0 commit comments