<s> try : <EOL> import numpy as np <EOL> except ImportError : <EOL> np = None <EOL> if np : <EOL> try : <EOL> import pandas as pd <EOL> except ImportError : <EOL> pd = None <EOL> from . import Converter , Options <EOL> class NumpyArrayConverter ( Converter ) : <EOL> writes_types = np . ndarray <EOL> @ classmethod <EOL> def base_reader ( cls , options ) : <EOL> return ( <EOL> super ( NumpyArrayConverter , cls ) . base_reader ( <EOL> Options ( options ) <EOL> . defaults ( empty = np . nan ) <EOL> ) <EOL> ) <EOL> @ classmethod <EOL> def read_value ( cls , value , options ) : <EOL> dtype = options . get ( '<STR_LIT>' , None ) <EOL> copy = options . get ( '<STR_LIT>' , True ) <EOL> order = options . get ( '<STR_LIT>' , None ) <EOL> ndim = options . get ( '<STR_LIT>' , None ) or <NUM_LIT:0> <EOL> return np . array ( value , dtype = dtype , copy = copy , order = order , ndmin = ndim ) <EOL> @ classmethod <EOL> def write_value ( cls , value , options ) : <EOL> try : <EOL> value = np . where ( np . isnan ( value ) , None , value ) <EOL> value = value . tolist ( ) <EOL> except TypeError : <EOL> if pd : <EOL> value [ pd . isnull ( value ) ] = None <EOL> value = value . tolist ( ) <EOL> else : <EOL> value = [ [ None if isinstance ( c , float ) and np . isnan ( c ) else c for c in row ] for row in value ] <EOL> return value <EOL> NumpyArrayConverter . register ( np . array , np . ndarray ) </s>
