Skip to content

TST: Use unicode literals in string test #10405

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
Jun 23, 2015
Merged
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
41 changes: 9 additions & 32 deletions pandas/tests/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,20 +747,18 @@ def test_isnumeric(self):
# 0x2605: ★ not number
# 0x1378: ፸ ETHIOPIC NUMBER SEVENTY
# 0xFF13: 3 Em 3
values = ['A', '3', unichr(0x00bc), unichr(0x2605),
unichr(0x1378), unichr(0xFF13), 'four']
values = ['A', '3', u'¼', u'★', u'፸', u'3', 'four']
s = Series(values)
numeric_e = [False, True, True, False, True, True, False]
decimal_e = [False, True, False, False, False, True, False]
tm.assert_series_equal(s.str.isnumeric(), Series(numeric_e))
tm.assert_series_equal(s.str.isdecimal(), Series(decimal_e))
unicodes = [u('A'), u('3'), unichr(0x00bc), unichr(0x2605),
unichr(0x1378), unichr(0xFF13), u('four')]

unicodes = [u'A', u'3', u'¼', u'★', u'፸', u'3', u'four']
self.assertEqual(s.str.isnumeric().tolist(), [v.isnumeric() for v in unicodes])
self.assertEqual(s.str.isdecimal().tolist(), [v.isdecimal() for v in unicodes])

values = ['A', np.nan, unichr(0x00bc), unichr(0x2605),
np.nan, unichr(0xFF13), 'four']
values = ['A', np.nan, u'¼', u'★', np.nan, u'3', 'four']
s = Series(values)
numeric_e = [False, np.nan, True, False, np.nan, True, False]
decimal_e = [False, np.nan, False, False, np.nan, True, False]
Expand Down Expand Up @@ -1950,33 +1948,16 @@ def test_encode_decode_errors(self):
tm.assert_series_equal(result, exp)

def test_normalize(self):
def unistr(codes):
# build unicode string from unichr
# we cannot use six.u() here because it escapes unicode
return ''.join([unichr(c) for c in codes])

values = ['ABC', # ASCII
unistr([0xFF21, 0xFF22, 0xFF23]), # ABC
unistr([0xFF11, 0xFF12, 0xFF13]), # 123
np.nan,
unistr([0xFF71, 0xFF72, 0xFF74])] # アイエ
values = ['ABC', u'ABC', u'123', np.nan, u'アイエ']
s = Series(values, index=['a', 'b', 'c', 'd', 'e'])

normed = [compat.u_safe('ABC'),
compat.u_safe('ABC'),
compat.u_safe('123'),
np.nan,
unistr([0x30A2, 0x30A4, 0x30A8])] # アイエ
normed = [u'ABC', u'ABC', u'123', np.nan, u'アイエ']
expected = Series(normed, index=['a', 'b', 'c', 'd', 'e'])

result = s.str.normalize('NFKC')
tm.assert_series_equal(result, expected)

expected = Series([compat.u_safe('ABC'),
unistr([0xFF21, 0xFF22, 0xFF23]), # ABC
unistr([0xFF11, 0xFF12, 0xFF13]), # 123
np.nan,
unistr([0xFF71, 0xFF72, 0xFF74])], # アイエ
expected = Series([u'ABC', u'ABC', u'123', np.nan, u'アイエ'],
index=['a', 'b', 'c', 'd', 'e'])

result = s.str.normalize('NFC')
Expand All @@ -1985,12 +1966,8 @@ def unistr(codes):
with tm.assertRaisesRegexp(ValueError, "invalid normalization form"):
s.str.normalize('xxx')

s = Index([unistr([0xFF21, 0xFF22, 0xFF23]), # ABC
unistr([0xFF11, 0xFF12, 0xFF13]), # 123
unistr([0xFF71, 0xFF72, 0xFF74])]) # アイエ
expected = Index([compat.u_safe('ABC'),
compat.u_safe('123'),
unistr([0x30A2, 0x30A4, 0x30A8])])
s = Index([u'ABC', u'123', u'アイエ'])
expected = Index([u'ABC', u'123', u'アイエ'])
result = s.str.normalize('NFKC')
tm.assert_index_equal(result, expected)

Expand Down