@@ -89,6 +89,9 @@ def _get_dtypes(fields_to_dtypes, fields):
89
89
dtypes = []
90
90
f2d = _FIELDS_TO_DTYPES .copy ()
91
91
f2d .update (fields_to_dtypes )
92
+ for k , v in f2d .items ():
93
+ if not issubclass (k , django .db .models .fields .Field ):
94
+ raise TypeError (f'Expected a type of field, not { k !r} ' )
92
95
for field in fields :
93
96
# Find the lowest subclass among the keys of f2d
94
97
t , dtype = object , object
@@ -138,7 +141,7 @@ def read_frame(qs, fieldnames=(), index_col=None, coerce_float=False,
138
141
defined in the ``__unicode__`` or ``__str__``
139
142
methods of the related class definition
140
143
141
- compress: boolean or a mapping, default False
144
+ compress: a false value, ``True``, or a mapping, default False
142
145
If a true value, infer NumPy data types [#]_ for Pandas dataframe
143
146
columns from the corresponding Django field types. For example, Django's
144
147
built in ``SmallIntgerField`` is cast to NumPy's ``int16``. If
@@ -202,6 +205,8 @@ def read_frame(qs, fieldnames=(), index_col=None, coerce_float=False,
202
205
recs = qs .iterator ()
203
206
204
207
if compress :
208
+ if not isinstance (compress , (bool , Mapping )):
209
+ raise TypeError (f'Ambiguous compress argument: { compress !r} ' )
205
210
if not isinstance (compress , Mapping ):
206
211
compress = {}
207
212
recs = np .array (list (recs ), dtype = _get_dtypes (compress , fields ))
0 commit comments