Skip to content

Commit 3e9c320

Browse files
committed
COMPAT: ensure platform it on 32-bit
TST: use 32bit_repr when printing formatting of sparse COMPAT: ensure consensus name when Indexes are union/intersected if possible COMPAT: skip some coercion tests on 32-bit closes #12927 closes #13047
1 parent 4e6b649 commit 3e9c320

File tree

7 files changed

+91
-10
lines changed

7 files changed

+91
-10
lines changed

doc/source/whatsnew/v0.18.1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ Bug Fixes
584584
- Bug in ``groupby`` where complex types are coerced to float (:issue:`12902`)
585585
- Bug in ``Series.map`` raises ``TypeError`` if its dtype is ``category`` or tz-aware ``datetime`` (:issue:`12473`)
586586

587-
587+
- Bugs on 32bit platforms for some test comparisons (:issue:`12972`)
588588
- Bug in index coercion when falling back from ``RangeIndex`` construction (:issue:`12893`)
589589
- Better error message in window functions when invalid argument (e.g. a float window) is passed (:issue:`12669`)
590590

pandas/core/series.py

+2
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,8 @@ def dot(self, other):
14871487
@Substitution(klass='Series', value='v')
14881488
@Appender(base._shared_docs['searchsorted'])
14891489
def searchsorted(self, v, side='left', sorter=None):
1490+
if sorter is not None:
1491+
sorter = com._ensure_platform_int(sorter)
14901492
return self._values.searchsorted(Series(v)._values,
14911493
side=side, sorter=sorter)
14921494

pandas/indexes/api.py

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ def conv(i):
7676
if not index.equals(other):
7777
return _unique_indices(indexes)
7878

79+
name = _get_consensus_names(indexes)[0]
80+
if name != index.name:
81+
index = index._shallow_copy(name=name)
7982
return index
8083
else:
8184
return _unique_indices(indexes)

pandas/indexes/base.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,21 @@ def __or__(self, other):
16631663
def __xor__(self, other):
16641664
return self.symmetric_difference(other)
16651665

1666+
def _get_consensus_name(self, other):
1667+
"""
1668+
Given 2 indexes, give a consensus name meaning
1669+
we take the not None one, or None if the names differ.
1670+
Return a new object if we are resetting the name
1671+
"""
1672+
if self.name != other.name:
1673+
if self.name is None or other.name is None:
1674+
name = self.name or other.name
1675+
else:
1676+
name = None
1677+
if self.name != name:
1678+
return other._shallow_copy(name=name)
1679+
return self
1680+
16661681
def union(self, other):
16671682
"""
16681683
Form the union of two Index objects and sorts if possible.
@@ -1688,10 +1703,10 @@ def union(self, other):
16881703
other = _ensure_index(other)
16891704

16901705
if len(other) == 0 or self.equals(other):
1691-
return self
1706+
return self._get_consensus_name(other)
16921707

16931708
if len(self) == 0:
1694-
return other
1709+
return other._get_consensus_name(self)
16951710

16961711
if not com.is_dtype_equal(self.dtype, other.dtype):
16971712
this = self.astype('O')
@@ -1774,7 +1789,7 @@ def intersection(self, other):
17741789
other = _ensure_index(other)
17751790

17761791
if self.equals(other):
1777-
return self
1792+
return self._get_consensus_name(other)
17781793

17791794
if not com.is_dtype_equal(self.dtype, other.dtype):
17801795
this = self.astype('O')

pandas/tests/formats/test_format.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import re
99

1010
from pandas.compat import (range, zip, lrange, StringIO, PY3,
11-
u, lzip, is_platform_windows)
11+
u, lzip, is_platform_windows,
12+
is_platform_32bit)
1213
import pandas.compat as compat
1314
import itertools
1415
from operator import methodcaller
@@ -45,6 +46,8 @@
4546

4647
import nose
4748

49+
use_32bit_repr = is_platform_windows() or is_platform_32bit()
50+
4851
_frame = DataFrame(tm.getSeriesData())
4952

5053

@@ -3758,7 +3761,7 @@ def test_to_string_header(self):
37583761
def test_sparse_max_row(self):
37593762
s = pd.Series([1, np.nan, np.nan, 3, np.nan]).to_sparse()
37603763
result = repr(s)
3761-
dtype = '' if is_platform_windows() else ', dtype=int32'
3764+
dtype = '' if use_32bit_repr else ', dtype=int32'
37623765
exp = ("0 1.0\n1 NaN\n2 NaN\n3 3.0\n"
37633766
"4 NaN\ndtype: float64\nBlockIndex\n"
37643767
"Block locations: array([0, 3]{0})\n"

pandas/tests/indexes/test_base.py

+57-4
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,23 @@ def test_intersection(self):
554554
result = idx1.intersection(idx2)
555555
self.assertTrue(result.equals(expected))
556556

557+
# preserve names
558+
first = self.strIndex[5:20]
559+
second = self.strIndex[:10]
560+
first.name = 'A'
561+
second.name = 'A'
562+
intersect = first.intersection(second)
563+
self.assertEqual(intersect.name, 'A')
564+
565+
second.name = 'B'
566+
intersect = first.intersection(second)
567+
self.assertIsNone(intersect.name)
568+
569+
first.name = None
570+
second.name = 'B'
571+
intersect = first.intersection(second)
572+
self.assertIsNone(intersect.name)
573+
557574
def test_union(self):
558575
first = self.strIndex[5:20]
559576
second = self.strIndex[:10]
@@ -578,15 +595,51 @@ def test_union(self):
578595
self.assertIs(union, first)
579596

580597
# preserve names
581-
first.name = 'A'
582-
second.name = 'A'
598+
first = Index(list('ab'), name='A')
599+
second = Index(list('ab'), name='B')
583600
union = first.union(second)
584-
self.assertEqual(union.name, 'A')
601+
self.assertIsNone(union.name)
585602

586-
second.name = 'B'
603+
first = Index(list('ab'), name='A')
604+
second = Index([], name='B')
587605
union = first.union(second)
588606
self.assertIsNone(union.name)
589607

608+
first = Index([], name='A')
609+
second = Index(list('ab'), name='B')
610+
union = first.union(second)
611+
self.assertIsNone(union.name)
612+
613+
first = Index(list('ab'))
614+
second = Index(list('ab'), name='B')
615+
union = first.union(second)
616+
self.assertEqual(union.name, 'B')
617+
618+
first = Index([])
619+
second = Index(list('ab'), name='B')
620+
union = first.union(second)
621+
self.assertEqual(union.name, 'B')
622+
623+
first = Index(list('ab'))
624+
second = Index([], name='B')
625+
union = first.union(second)
626+
self.assertEqual(union.name, 'B')
627+
628+
first = Index(list('ab'), name='A')
629+
second = Index(list('ab'))
630+
union = first.union(second)
631+
self.assertEqual(union.name, 'A')
632+
633+
first = Index(list('ab'), name='A')
634+
second = Index([])
635+
union = first.union(second)
636+
self.assertEqual(union.name, 'A')
637+
638+
first = Index([], name='A')
639+
second = Index(list('ab'))
640+
union = first.union(second)
641+
self.assertEqual(union.name, 'A')
642+
590643
def test_add(self):
591644

592645
# - API change GH 8226

pandas/tests/indexing/test_coercion.py

+5
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,11 @@ def _assert_replace_conversion(self, from_key, to_key, how):
473473
# TODO_GH12747 The result must be int?
474474
(from_key == 'bool' and to_key in ('int64'))):
475475

476+
# buggy on 32-bit
477+
if tm.is_platform_32bit():
478+
raise nose.SkipTest("32-bit platform buggy: {0} -> {1}".format
479+
(from_key, to_key))
480+
476481
# Expected: do not downcast by replacement
477482
exp = pd.Series(self.rep[to_key], index=index,
478483
name='yyy', dtype=from_key)

0 commit comments

Comments
 (0)