@@ -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-
24442323class GaussianKDE (object ):
24452324 """
24462325 Representation of a kernel-density estimate using Gaussian kernels.
0 commit comments