Skip to content

Commit 7b5ca80

Browse files
authored
COMPAT: Warnings (#18247)
* COMPAT: remove deprecation warnings for numpy 1.14 COMPAT: sas7bdat warning of unclosed file with 0 rows * COMPAT: json warning * COMPAT: numpy warnings on invalid indexer in computation
1 parent 9e3ad63 commit 7b5ca80

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

pandas/core/computation/eval.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""Top level ``eval`` module.
44
"""
55

6+
import warnings
67
import tokenize
78
from pandas.io.formats.printing import pprint_thing
89
from pandas.core.computation.scope import _ensure_scope
@@ -303,7 +304,8 @@ def eval(expr, parser='pandas', engine=None, truediv=True,
303304
"if there is no assignment")
304305

305306
# assign if needed
306-
if env.target is not None and parsed_expr.assigner is not None:
307+
assigner = parsed_expr.assigner
308+
if env.target is not None and assigner is not None:
307309
target_modified = True
308310

309311
# if returning a copy, copy only on the first assignment
@@ -317,22 +319,25 @@ def eval(expr, parser='pandas', engine=None, truediv=True,
317319

318320
# TypeError is most commonly raised (e.g. int, list), but you
319321
# get IndexError if you try to do this assignment on np.ndarray.
322+
# we will ignore numpy warnings here; e.g. if trying
323+
# to use a non-numeric indexer
320324
try:
321-
target[parsed_expr.assigner] = ret
325+
with warnings.catch_warnings(record=True):
326+
target[assigner] = ret
322327
except (TypeError, IndexError):
323328
raise ValueError("Cannot assign expression output to target")
324329

325330
if not resolvers:
326-
resolvers = ({parsed_expr.assigner: ret},)
331+
resolvers = ({assigner: ret},)
327332
else:
328333
# existing resolver needs updated to handle
329334
# case of mutating existing column in copy
330335
for resolver in resolvers:
331-
if parsed_expr.assigner in resolver:
332-
resolver[parsed_expr.assigner] = ret
336+
if assigner in resolver:
337+
resolver[assigner] = ret
333338
break
334339
else:
335-
resolvers += ({parsed_expr.assigner: ret},)
340+
resolvers += ({assigner: ret},)
336341

337342
ret = None
338343
first_expr = False

pandas/core/groupby.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,10 @@ def size(self):
19131913
"""
19141914
ids, _, ngroup = self.group_info
19151915
ids = _ensure_platform_int(ids)
1916-
out = np.bincount(ids[ids != -1], minlength=ngroup or None)
1916+
if ngroup:
1917+
out = np.bincount(ids[ids != -1], minlength=ngroup)
1918+
else:
1919+
out = ids
19171920
return Series(out,
19181921
index=self.result_index,
19191922
dtype='int64')

pandas/io/json/json.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ def _parse_numpy(self):
764764
if orient == "columns":
765765
args = loads(json, dtype=None, numpy=True, labelled=True,
766766
precise_float=self.precise_float)
767-
if args:
767+
if len(args):
768768
args = (args[0].T, args[2], args[1])
769769
self.obj = DataFrame(*args)
770770
elif orient == "split":

pandas/io/sas/sas7bdat.py

+1
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ def read(self, nrows=None):
596596
nrows = self.row_count
597597

598598
if len(self.column_types) == 0:
599+
self.close()
599600
raise EmptyDataError("No columns to parse from file")
600601

601602
if self._current_row_in_file_index >= self.row_count:

0 commit comments

Comments
 (0)