Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit52413e0

Browse files
authored
Merge pull request#8591 from story645/cattests
shims for categorical support for numpy < 1.8
2 parents48584c7 +cc27905 commit52413e0

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

‎lib/matplotlib/category.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,35 @@
44
"""
55
from __future__import (absolute_import,division,print_function,
66
unicode_literals)
7-
87
importsix
98

109
importnumpyasnp
1110

12-
importmatplotlib.cbookascbook
1311
importmatplotlib.unitsasunits
1412
importmatplotlib.tickerasticker
1513

14+
# np 1.6/1.7 support
15+
fromdistutils.versionimportLooseVersion
16+
importcollections
17+
18+
19+
ifLooseVersion(np.__version__)>=LooseVersion('1.8.0'):
20+
defshim_array(data):
21+
returnnp.array(data,dtype=np.unicode)
22+
else:
23+
defshim_array(data):
24+
if (isinstance(data,six.string_types)or
25+
notisinstance(data,collections.Iterable)):
26+
data= [data]
27+
try:
28+
data= [str(d)fordindata]
29+
exceptUnicodeEncodeError:
30+
# this yields gibberish but unicode text doesn't
31+
# render under numpy1.6 anyway
32+
data= [d.encode('utf-8','ignore').decode('utf-8')
33+
fordindata]
34+
returnnp.array(data,dtype=np.unicode)
35+
1636

1737
classStrCategoryConverter(units.ConversionInterface):
1838
@staticmethod
@@ -25,7 +45,8 @@ def convert(value, unit, axis):
2545
ifisinstance(value,six.string_types):
2646
returnvmap[value]
2747

28-
vals=np.array(value,dtype=np.unicode)
48+
vals=shim_array(value)
49+
2950
forlab,locinvmap.items():
3051
vals[vals==lab]=loc
3152

@@ -81,8 +102,7 @@ def update(self, new_data):
81102
self._set_seq_locs(new_data,value)
82103

83104
def_set_seq_locs(self,data,value):
84-
strdata=np.array(data,dtype=np.unicode)
85-
# np.unique makes dateframes work
105+
strdata=shim_array(data)
86106
new_s= [dfordinnp.unique(strdata)ifdnotinself.seq]
87107
fornsinnew_s:
88108
self.seq.append(ns)

‎lib/matplotlib/tests/test_category.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
from __future__import (absolute_import,division,print_function,
44
unicode_literals)
55

6-
fromdistutils.versionimportLooseVersion
7-
86
importpytest
97
importnumpyasnp
108

@@ -14,11 +12,6 @@
1412
importunittest
1513

1614

17-
needs_new_numpy=pytest.mark.xfail(
18-
LooseVersion(np.__version__)<LooseVersion('1.8.0'),
19-
reason='NumPy < 1.8.0 is broken.')
20-
21-
2215
classTestUnitData(object):
2316
testdata= [("hello world", ["hello world"], [0]),
2417
("Здравствуйте мир", ["Здравствуйте мир"], [0]),
@@ -28,14 +21,12 @@ class TestUnitData(object):
2821

2922
ids= ["single","unicode","mixed"]
3023

31-
@needs_new_numpy
3224
@pytest.mark.parametrize("data, seq, locs",testdata,ids=ids)
3325
deftest_unit(self,data,seq,locs):
3426
act=cat.UnitData(data)
3527
assertact.seq==seq
3628
assertact.locs==locs
3729

38-
@needs_new_numpy
3930
deftest_update_map(self):
4031
data= ['a','d']
4132
oseq= ['a','d']
@@ -87,7 +78,6 @@ class TestStrCategoryConverter(object):
8778
defmock_axis(self,request):
8879
self.cc=cat.StrCategoryConverter()
8980

90-
@needs_new_numpy
9181
@pytest.mark.parametrize("data, unitmap, exp",testdata,ids=ids)
9282
deftest_convert(self,data,unitmap,exp):
9383
MUD=MockUnitData(unitmap)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp