@@ -2107,6 +2107,20 @@ def rec_drop_fields(rec, names):
21072107
21082108 return newrec
21092109
2110+ def rec_keep_fields (rec , names ):
2111+ """
2112+ Return a new numpy record array with only fields listed in names
2113+ """
2114+
2115+ if cbook .is_string_like (names ):
2116+ names = names .split (',' )
2117+
2118+ arrays = []
2119+ for name in names :
2120+ arrays .append (rec [name ])
2121+
2122+ return np .rec .fromarrays (arrays , names = names )
2123+
21102124
21112125
21122126def rec_groupby (r , groupby , stats ):
@@ -2699,7 +2713,7 @@ def csvformat_factory(format):
26992713 format .fmt = '%r'
27002714 return format
27012715
2702- def rec2txt (r , header = None , padding = 3 , precision = 3 ):
2716+ def rec2txt (r , header = None , padding = 3 , precision = 3 , fields = None ):
27032717 """
27042718 Returns a textual representation of a record array.
27052719
@@ -2714,6 +2728,10 @@ def rec2txt(r, header=None, padding=3, precision=3):
27142728 list of integers to apply precision individually.
27152729 Precision for non-floats is simply ignored.
27162730
2731+ *fields* : if not None, a list of field names to print. fields
2732+ can be a list of strings like ['field1', 'field2'] or a single
2733+ comma separated string like 'field1,field2'
2734+
27172735 Example::
27182736
27192737 precision=[0,2,3]
@@ -2725,6 +2743,9 @@ def rec2txt(r, header=None, padding=3, precision=3):
27252743 XYZ 6.32 -0.076
27262744 """
27272745
2746+ if fields is not None :
2747+ r = rec_keep_fields (r , fields )
2748+
27282749 if cbook .is_numlike (precision ):
27292750 precision = [precision ]* len (r .dtype )
27302751
0 commit comments