Skip to content

COMPAT: Warnings #18247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions pandas/core/computation/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Top level ``eval`` module.
"""

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

# assign if needed
if env.target is not None and parsed_expr.assigner is not None:
assigner = parsed_expr.assigner
if env.target is not None and assigner is not None:
target_modified = True

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

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

if not resolvers:
resolvers = ({parsed_expr.assigner: ret},)
resolvers = ({assigner: ret},)
else:
# existing resolver needs updated to handle
# case of mutating existing column in copy
for resolver in resolvers:
if parsed_expr.assigner in resolver:
resolver[parsed_expr.assigner] = ret
if assigner in resolver:
resolver[assigner] = ret
break
else:
resolvers += ({parsed_expr.assigner: ret},)
resolvers += ({assigner: ret},)

ret = None
first_expr = False
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,10 @@ def size(self):
"""
ids, _, ngroup = self.group_info
ids = _ensure_platform_int(ids)
out = np.bincount(ids[ids != -1], minlength=ngroup or None)
if ngroup:
out = np.bincount(ids[ids != -1], minlength=ngroup)
else:
out = ids
return Series(out,
index=self.result_index,
dtype='int64')
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/json/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def _parse_numpy(self):
if orient == "columns":
args = loads(json, dtype=None, numpy=True, labelled=True,
precise_float=self.precise_float)
if args:
if len(args):
args = (args[0].T, args[2], args[1])
self.obj = DataFrame(*args)
elif orient == "split":
Expand Down
1 change: 1 addition & 0 deletions pandas/io/sas/sas7bdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ def read(self, nrows=None):
nrows = self.row_count

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

if self._current_row_in_file_index >= self.row_count:
Expand Down