-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
Numindexname #13205
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
Numindexname #13205
Changes from all commits
b6c9233
6d75e55
757d105
3320727
bea8101
9d93fea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,6 +205,53 @@ def test_hash_error(self): | |
type(ind).__name__): | ||
hash(ind) | ||
|
||
def test_copy_name(self): | ||
# Check that "name" argument passed at initialization is honoured | ||
# GH12309 | ||
for name, index in compat.iteritems(self.indices): | ||
if isinstance(index, MultiIndex): | ||
continue | ||
|
||
|
||
first = index.__class__(index, copy=True, name='mario') | ||
second = first.__class__(first, copy=False) | ||
|
||
# Even though "copy=False", we want a new object. | ||
self.assertIsNot(first, second) | ||
# Not using tm.assert_index_equal() since names differ: | ||
self.assertTrue(index.equals(first)) | ||
|
||
self.assertEqual(first.name, 'mario') | ||
self.assertEqual(second.name, 'mario') | ||
|
||
s1 = Series(2, index=first) | ||
s2 = Series(3, index=second[:-1]) | ||
if not isinstance(index, CategoricalIndex): # See GH13365 | ||
s3 = s1 * s2 | ||
self.assertEqual(s3.index.name, 'mario') | ||
|
||
def test_ensure_copied_data(self): | ||
# Check the "copy" argument of each Index.__new__ is honoured | ||
# GH12309 | ||
for name, index in compat.iteritems(self.indices): | ||
init_kwargs = {} | ||
if isinstance(index, PeriodIndex): | ||
# Needs "freq" specification: | ||
init_kwargs['freq'] = index.freq | ||
elif isinstance(index, (RangeIndex, MultiIndex, CategoricalIndex)): | ||
# RangeIndex cannot be initialized from data | ||
# MultiIndex and CategoricalIndex are tested separately | ||
continue | ||
|
||
index_type = index.__class__ | ||
result = index_type(index.values, copy=True, **init_kwargs) | ||
tm.assert_index_equal(index, result) | ||
tm.assert_numpy_array_equal(index.values, result.values, | ||
check_same='copy') | ||
|
||
result = index_type(index.values, copy=False, **init_kwargs) | ||
tm.assert_numpy_array_equal(index.values, result.values, | ||
check_same='same') | ||
|
||
def test_copy_and_deepcopy(self): | ||
from copy import copy, deepcopy | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -315,6 +315,17 @@ def test_numpy_array_equal_object_message(self): | |
with assertRaisesRegexp(AssertionError, expected): | ||
assert_almost_equal(a, b) | ||
|
||
def test_numpy_array_equal_copy_flag(self): | ||
a = np.array([1, 2, 3]) | ||
b = a.copy() | ||
c = a.view() | ||
expected = 'array\(\[1, 2, 3\]\) is not array\(\[1, 2, 3\]\)' | ||
with assertRaisesRegexp(AssertionError, expected): | ||
assert_numpy_array_equal(a, b, check_same='same') | ||
expected = 'array\(\[1, 2, 3\]\) is array\(\[1, 2, 3\]\)' | ||
with assertRaisesRegexp(AssertionError, expected): | ||
|
||
assert_numpy_array_equal(a, c, check_same='copy') | ||
|
||
def test_assert_almost_equal_iterable_message(self): | ||
|
||
expected = """Iterable are different | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what the heck is this?