Skip to content

Easy warning fixups for mypy #27402

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 1 commit into from
Jul 15, 2019
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
6 changes: 2 additions & 4 deletions pandas/core/computation/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,15 @@ def pr(left, right):

k = klass
if isinstance(left, ConditionBinOp):
if isinstance(left, ConditionBinOp) and isinstance(
right, ConditionBinOp
):
if isinstance(right, ConditionBinOp):
k = JointConditionBinOp
elif isinstance(left, k):
return left
elif isinstance(right, k):
return right

elif isinstance(left, FilterBinOp):
if isinstance(left, FilterBinOp) and isinstance(right, FilterBinOp):
if isinstance(right, FilterBinOp):
k = JointFilterBinOp
elif isinstance(left, k):
return left
Expand Down
4 changes: 1 addition & 3 deletions pandas/io/json/_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def nested_to_record(


def json_normalize(
data: List[Dict],
data: Union[Dict, List[Dict]],
record_path: Optional[Union[str, List]] = None,
meta: Optional[Union[str, List]] = None,
meta_prefix: Optional[str] = None,
Expand Down Expand Up @@ -280,8 +280,6 @@ def _pull_field(js, spec):
lengths = []

meta_vals = defaultdict(list) # type: DefaultDict
if not isinstance(sep, str):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this would break code if someone tried to provide a non-str sep but that's not documented and unclear why someone would try that anyway

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could it be a remnant of py2 compatibility? for public methods should we allow bytes in all places where a string is expected?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure but on closer inspection doesn't seem to work in general case anyway:

>>> json_normalize({ 'foo' : { 'bar' : 0 } }, sep=b'.')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/williamayd/clones/pandas/pandas/io/json/_normalize.py", line 266, in json_normalize
    data = nested_to_record(data, sep=sep, max_level=max_level)
  File "/Users/williamayd/clones/pandas/pandas/io/json/_normalize.py", line 106, in nested_to_record
    new_d.update(nested_to_record(v, newkey, sep, level + 1, max_level))
  File "/Users/williamayd/clones/pandas/pandas/io/json/_normalize.py", line 91, in nested_to_record
    newkey = prefix + sep + k
TypeError: can only concatenate str (not "bytes") to str

So just seems like a mistake

sep = str(sep)
meta_keys = [sep.join(val) for val in meta]

def _recursive_extract(data, path, seen_meta, level=0):
Expand Down