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

Skip to content

Commit f1c3ee3

Browse files
committed
Remove mlab.rec2txt
1 parent f882efd commit f1c3ee3

3 files changed

Lines changed: 1 addition & 135 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
@@ -40,4 +40,5 @@ in Matplotlib 2.2 has been removed. See below for a list:
4040
- `mlab.poly_below`
4141
- `mlab.inside_poly`
4242
- `mlab.rec2csv` (use numpy.recarray.tofile instead)
43+
- `mlab.rec2text` (use numpy.recarray.tofile instead)
4344
- `mlab.donothing_callback`

lib/matplotlib/mlab.py

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,127 +2320,6 @@ def csvformat_factory(format):
23202320
return format
23212321

23222322

2323-
@cbook.deprecated("2.2", alternative='numpy.recarray.tofile')
2324-
def rec2txt(r, header=None, padding=3, precision=3, fields=None):
2325-
"""
2326-
Returns a textual representation of a record array.
2327-
2328-
Parameters
2329-
----------
2330-
r: numpy recarray
2331-
2332-
header: list
2333-
column headers
2334-
2335-
padding:
2336-
space between each column
2337-
2338-
precision: number of decimal places to use for floats.
2339-
Set to an integer to apply to all floats. Set to a
2340-
list of integers to apply precision individually.
2341-
Precision for non-floats is simply ignored.
2342-
2343-
fields : list
2344-
If not None, a list of field names to print. fields
2345-
can be a list of strings like ['field1', 'field2'] or a single
2346-
comma separated string like 'field1,field2'
2347-
2348-
Examples
2349-
--------
2350-
2351-
For ``precision=[0,2,3]``, the output is ::
2352-
2353-
ID Price Return
2354-
ABC 12.54 0.234
2355-
XYZ 6.32 -0.076
2356-
"""
2357-
2358-
if fields is not None:
2359-
r = rec_keep_fields(r, fields)
2360-
2361-
if cbook.is_numlike(precision):
2362-
precision = [precision]*len(r.dtype)
2363-
2364-
def get_type(item, atype=int):
2365-
tdict = {None: int, int: float, float: str}
2366-
try:
2367-
atype(str(item))
2368-
except Exception:
2369-
return get_type(item, tdict[atype])
2370-
return atype
2371-
2372-
def get_justify(colname, column, precision):
2373-
ntype = column.dtype
2374-
2375-
if np.issubdtype(ntype, np.character):
2376-
fixed_width = int(ntype.str[2:])
2377-
length = max(len(colname), fixed_width)
2378-
return 0, length+padding, "%s" # left justify
2379-
2380-
if np.issubdtype(ntype, np.integer):
2381-
length = max(len(colname),
2382-
np.max(list(map(len, list(map(str, column))))))
2383-
return 1, length+padding, "%d" # right justify
2384-
2385-
if np.issubdtype(ntype, np.floating):
2386-
fmt = "%." + str(precision) + "f"
2387-
length = max(
2388-
len(colname),
2389-
np.max(list(map(len, list(map(lambda x: fmt % x, column)))))
2390-
)
2391-
return 1, length+padding, fmt # right justify
2392-
2393-
return (0,
2394-
max(len(colname),
2395-
np.max(list(map(len, list(map(str, column))))))+padding,
2396-
"%s")
2397-
2398-
if header is None:
2399-
header = r.dtype.names
2400-
2401-
justify_pad_prec = [get_justify(header[i], r.__getitem__(colname),
2402-
precision[i])
2403-
for i, colname in enumerate(r.dtype.names)]
2404-
2405-
justify_pad_prec_spacer = []
2406-
for i in range(len(justify_pad_prec)):
2407-
just, pad, prec = justify_pad_prec[i]
2408-
if i == 0:
2409-
justify_pad_prec_spacer.append((just, pad, prec, 0))
2410-
else:
2411-
pjust, ppad, pprec = justify_pad_prec[i-1]
2412-
if pjust == 0 and just == 1:
2413-
justify_pad_prec_spacer.append((just, pad-padding, prec, 0))
2414-
elif pjust == 1 and just == 0:
2415-
justify_pad_prec_spacer.append((just, pad, prec, padding))
2416-
else:
2417-
justify_pad_prec_spacer.append((just, pad, prec, 0))
2418-
2419-
def format(item, just_pad_prec_spacer):
2420-
just, pad, prec, spacer = just_pad_prec_spacer
2421-
if just == 0:
2422-
return spacer*' ' + str(item).ljust(pad)
2423-
else:
2424-
if get_type(item) == float:
2425-
item = (prec % float(item))
2426-
elif get_type(item) == int:
2427-
item = (prec % int(item))
2428-
2429-
return item.rjust(pad)
2430-
2431-
textl = []
2432-
textl.append(''.join([format(colitem, justify_pad_prec_spacer[j])
2433-
for j, colitem in enumerate(header)]))
2434-
for i, row in enumerate(r):
2435-
textl.append(''.join([format(colitem, justify_pad_prec_spacer[j])
2436-
for j, colitem in enumerate(row)]))
2437-
if i == 0:
2438-
textl[0] = textl[0].rstrip()
2439-
2440-
text = os.linesep.join(textl)
2441-
return text
2442-
2443-
24442323
class GaussianKDE(object):
24452324
"""
24462325
Representation of a kernel-density estimate using Gaussian kernels.

lib/matplotlib/tests/test_mlab.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,6 @@ def test_csv2rec_dates(tempcsv, input, kwargs):
193193
assert_array_equal(array['a'].tolist(), expected)
194194

195195

196-
def test_rec2txt_basic():
197-
a = np.array([(1.0, 2, 'foo', 'bing'),
198-
(2.0, 3, 'bar', 'blah')],
199-
dtype=np.dtype([('x', np.float32),
200-
('y', np.int8),
201-
('s', str, 3),
202-
('s2', str, 4)]))
203-
truth = (' x y s s2\n'
204-
' 1.000 2 foo bing \n'
205-
' 2.000 3 bar blah ').splitlines()
206-
with pytest.warns(MatplotlibDeprecationWarning):
207-
assert mlab.rec2txt(a).splitlines() == truth
208-
209-
210196
class TestWindow(object):
211197
def setup(self):
212198
np.random.seed(0)

0 commit comments

Comments
 (0)