Skip to content

Commit 131f9dd

Browse files
committed
Python 2.5 compatibility fix for mlab.py
svn path=/trunk/matplotlib/; revision=3386
1 parent 8c3f33e commit 131f9dd

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2007-06-11 Python 2.5 compatibility fix for mlab.py - EF
2+
13
2007-06-10 In matplotlibrc file, use 'dashed' | 'solid' instead
24
of a pair of floats for contour.negative_linestyle - EF
35

lib/matplotlib/cbook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def to_filehandle(fname):
172172
fh = fname
173173
else:
174174
raise ValueError('fname must be a string or file handle')
175-
return fh
175+
return fh
176176

177177
def flatten(seq, scalarp=is_scalar):
178178
"""

lib/matplotlib/mlab.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@
7676
from numerix.mlab import hanning, cov, diff, svd, rand, std
7777
from numerix.fft import fft, inverse_fft
7878

79-
from cbook import iterable, is_string_like, to_filehandle, set
79+
from cbook import iterable, is_string_like, to_filehandle
80+
81+
try: set
82+
except NameError:
83+
from sets import Set as set
84+
8085

8186

8287
def mean(x, dim=None):
@@ -1280,7 +1285,7 @@ def save(fname, X, fmt='%.18e',delimiter=' '):
12801285
X.shape = origShape
12811286

12821287

1283-
1288+
12841289

12851290
def load(fname,comments='#',delimiter=None, converters=None,skiprows=0,
12861291
usecols=None, unpack=False):
@@ -1364,7 +1369,7 @@ def csv2rec(fname, comments='#', skiprows=0, checkrows=5, delimiter=','):
13641369
numpy recarray.
13651370
13661371
The data must be regular, same number of values in every row
1367-
1372+
13681373
A header row is required to automatically assign the recarray
13691374
names. The headers will be lower cased, spaces will be converted
13701375
to underscores, and illegal attribute name characters removed.
@@ -1376,7 +1381,7 @@ def csv2rec(fname, comments='#', skiprows=0, checkrows=5, delimiter=','):
13761381
in the file
13771382
13781383
skiprows - is the number of rows from the top to skip
1379-
1384+
13801385
checkrows - is the number of rows to check to validate the column
13811386
data type. When set to zero all rows are validated.
13821387
@@ -1386,8 +1391,8 @@ def csv2rec(fname, comments='#', skiprows=0, checkrows=5, delimiter=','):
13861391
import numpy
13871392
import dateutil.parser
13881393
parsedate = dateutil.parser.parse
1389-
1390-
1394+
1395+
13911396
fh = to_filehandle(fname)
13921397
reader = csv.reader(fh, delimiter=delimiter)
13931398

@@ -1410,7 +1415,7 @@ def get_func(item, func):
14101415
if func==str:
14111416
raise ValueError('Could not find a working conversion function')
14121417
else: return get_func(item, funcmap[func]) # recurse
1413-
else: return func
1418+
else: return func
14141419

14151420

14161421
def get_converters(reader):
@@ -1427,40 +1432,40 @@ def get_converters(reader):
14271432
return converters
14281433

14291434

1430-
# Get header and remove invalid characters
1435+
# Get header and remove invalid characters
14311436
header = reader.next()
14321437
# remove these chars
14331438
delete = set("""~!@#$%^&*()-=+~\|]}[{';: /?.>,<""")
14341439
delete.add('"')
14351440

14361441
names = []
1437-
1442+
14381443
for i, item in enumerate(header):
14391444
item = item.strip().lower().replace(' ', '_')
14401445
item = ''.join([c for c in item if c not in delete])
14411446
if not len(item):
14421447
item = 'column%d'%i
14431448
names.append(item)
1444-
1449+
14451450
# get the converter functions by inspecting checkrows
14461451
converters = get_converters(reader)
14471452
if converters is None:
14481453
raise ValueError('Could not find any valid data in CSV file')
1449-
1454+
14501455
# reset the reader and start over
14511456
fh.seek(0)
14521457
process_skiprows(reader)
14531458
skipheader = reader.next()
1454-
1459+
14551460
# iterate over the remaining rows and convert the data to date
14561461
# objects, ints, or floats as approriate
1457-
rows = []
1462+
rows = []
14581463
for i, row in enumerate(reader):
14591464
if not len(row): continue
14601465
if row[0].startswith(comments): continue
14611466
rows.append([func(val) for func, val in zip(converters, row)])
14621467
fh.close()
1463-
1468+
14641469
r = numpy.rec.fromrecords(rows, names=names)
14651470
return r
14661471

0 commit comments

Comments
 (0)