Skip to content

Commit

Permalink
add else statement
Browse files Browse the repository at this point in the history
  • Loading branch information
reidy-p committed Nov 22, 2017
1 parent ec907a4 commit 2b8190d
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ def _maybe_coerce_merge_keys(self):
# the same, then proceed
if is_numeric_dtype(lk) and is_numeric_dtype(rk):
if lk.dtype.kind == rk.dtype.kind:
continue
pass

# check whether ints and floats
elif is_integer_dtype(rk) and is_float_dtype(lk):
Expand All @@ -920,21 +920,18 @@ def _maybe_coerce_merge_keys(self):
'columns where the float values '
'are not equal to their int '
'representation', UserWarning)
continue
pass

elif is_float_dtype(rk) and is_integer_dtype(lk):
if not (rk == rk.astype(lk.dtype)).all():
warnings.warn('You are merging on int and float '
'columns where the float values '
'are not equal to their int '
'representation', UserWarning)
continue
pass

# let's infer and see if we are ok
elif lib.infer_dtype(lk) == lib.infer_dtype(rk):
continue

else:
pass

# Houston, we have a problem!
Expand All @@ -944,14 +941,15 @@ def _maybe_coerce_merge_keys(self):
# then we would lose type information on some
# columns, and end up trying to merge
# incompatible dtypes. See GH 16900.
if name in self.left.columns:
typ = lk.categories.dtype if lk_is_cat else object
self.left = self.left.assign(
**{name: self.left[name].astype(typ)})
if name in self.right.columns:
typ = rk.categories.dtype if rk_is_cat else object
self.right = self.right.assign(
**{name: self.right[name].astype(typ)})
else:
if name in self.left.columns:
typ = lk.categories.dtype if lk_is_cat else object
self.left = self.left.assign(
**{name: self.left[name].astype(typ)})
if name in self.right.columns:
typ = rk.categories.dtype if rk_is_cat else object
self.right = self.right.assign(
**{name: self.right[name].astype(typ)})

def _validate_specification(self):
# Hm, any way to make this logic less complicated??
Expand Down

0 comments on commit 2b8190d

Please sign in to comment.