Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f882efd

Browse files
committed
Remove mlab.rec2csv
1 parent 3d8bce1 commit f882efd

4 files changed

Lines changed: 2 additions & 99 deletions

File tree

doc/api/next_api_changes/2018-09-18-DS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ in Matplotlib 2.2 has been removed. See below for a list:
3939
- `mlab.poly_between`
4040
- `mlab.poly_below`
4141
- `mlab.inside_poly`
42+
- `mlab.rec2csv` (use numpy.recarray.tofile instead)
4243
- `mlab.donothing_callback`

lib/matplotlib/mlab.py

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,78 +2441,6 @@ def format(item, just_pad_prec_spacer):
24412441
return text
24422442

24432443

2444-
@cbook.deprecated("2.2", alternative='numpy.recarray.tofile')
2445-
def rec2csv(r, fname, delimiter=',', formatd=None, missing='',
2446-
missingd=None, withheader=True):
2447-
"""
2448-
Save the data from numpy recarray *r* into a
2449-
comma-/space-/tab-delimited file. The record array dtype names
2450-
will be used for column headers.
2451-
2452-
*fname*: can be a filename or a file handle. Support for gzipped
2453-
files is automatic, if the filename ends in '.gz'
2454-
2455-
*withheader*: if withheader is False, do not write the attribute
2456-
names in the first row
2457-
2458-
for formatd type FormatFloat, we override the precision to store
2459-
full precision floats in the CSV file
2460-
2461-
See Also
2462-
--------
2463-
:func:`csv2rec`
2464-
For information about *missing* and *missingd*, which can be used to
2465-
fill in masked values into your CSV file.
2466-
"""
2467-
2468-
delimiter = str(delimiter)
2469-
2470-
if missingd is None:
2471-
missingd = dict()
2472-
2473-
def with_mask(func):
2474-
def newfunc(val, mask, mval):
2475-
if mask:
2476-
return mval
2477-
else:
2478-
return func(val)
2479-
return newfunc
2480-
2481-
if r.ndim != 1:
2482-
raise ValueError('rec2csv only operates on 1 dimensional recarrays')
2483-
2484-
formatd = get_formatd(r, formatd)
2485-
funcs = []
2486-
for i, name in enumerate(r.dtype.names):
2487-
funcs.append(with_mask(csvformat_factory(formatd[name]).tostr))
2488-
2489-
fh, opened = cbook.to_filehandle(fname, 'wb', return_opened=True)
2490-
writer = csv.writer(fh, delimiter=delimiter)
2491-
header = r.dtype.names
2492-
if withheader:
2493-
writer.writerow(header)
2494-
2495-
# Our list of specials for missing values
2496-
mvals = []
2497-
for name in header:
2498-
mvals.append(missingd.get(name, missing))
2499-
2500-
ismasked = False
2501-
if len(r):
2502-
row = r[0]
2503-
ismasked = hasattr(row, '_fieldmask')
2504-
2505-
for row in r:
2506-
if ismasked:
2507-
row, rowmask = row.item(), row._fieldmask.item()
2508-
else:
2509-
rowmask = [False] * len(row)
2510-
writer.writerow([func(val, mask, mval) for func, val, mask, mval
2511-
in zip(funcs, row, rowmask, mvals)])
2512-
if opened:
2513-
fh.close()
2514-
2515-
25162444
class GaussianKDE(object):
25172445
"""
25182446
Representation of a kernel-density estimate using Gaussian kernels.

lib/matplotlib/pylab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@
235235
frange,
236236
identity, ispower2, isvector, l1norm,
237237
l2norm, log2, movavg, norm_flat,
238-
rec2csv, rec_append_fields, rec_drop_fields, rec_join, rms_flat,
238+
rec_append_fields, rec_drop_fields, rec_join, rms_flat,
239239
window_hanning, window_none)
240240

241241
from matplotlib import cbook, mlab, pyplot as plt

lib/matplotlib/tests/test_mlab.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -150,32 +150,6 @@ def tempcsv():
150150
yield fd
151151

152152

153-
def test_recarray_csv_roundtrip(tempcsv):
154-
expected = np.recarray((99,), [('x', float), ('y', float), ('t', float)])
155-
# initialising all values: uninitialised memory sometimes produces
156-
# floats that do not round-trip to string and back.
157-
expected['x'][:] = np.linspace(-1e9, -1, 99)
158-
expected['y'][:] = np.linspace(1, 1e9, 99)
159-
expected['t'][:] = np.linspace(0, 0.01, 99)
160-
with pytest.warns(MatplotlibDeprecationWarning):
161-
mlab.rec2csv(expected, tempcsv)
162-
tempcsv.seek(0)
163-
actual = mlab.csv2rec(tempcsv)
164-
165-
assert_allclose(expected['x'], actual['x'])
166-
assert_allclose(expected['y'], actual['y'])
167-
assert_allclose(expected['t'], actual['t'])
168-
169-
170-
def test_rec2csv_bad_shape_ValueError(tempcsv):
171-
bad = np.recarray((99, 4), [('x', float), ('y', float)])
172-
173-
# the bad recarray should trigger a ValueError for having ndim > 1.
174-
with pytest.warns(MatplotlibDeprecationWarning):
175-
with pytest.raises(ValueError):
176-
mlab.rec2csv(bad, tempcsv)
177-
178-
179153
def test_csv2rec_names_with_comments(tempcsv):
180154

181155
tempcsv.write('# comment\n1,2,3\n4,5,6\n')

0 commit comments

Comments
 (0)