3
���hR �
@ s� d dl Z d dlZddlmZmZ ddlmZ ddlm Z m
Z
mZ dZe
ddd d
ddd
dddddg�Zddd�Zdd� Zdd� Zdd� Zdd� Zdd� Zd d!� Zd"d#� ZdS )$� N� )�conventions�Variable)�ops)�
basestring�unicode_type�OrderedDictz_.@+- !"#$%&\()*,:;<=>?[]^`{|}~Zbyte�char�shortZushort�intZuint�int64Zuint64Z floatreal�double�bool�stringZint32Zint8)r r c C s� t | j�}|tkrnt| }| j|�}d|ks4d|krB|| kj� sXd|krhtj|| � rhtd||f ��|} n| jjdkr�t j
jj| d�} | S )ae Coerce an array to a data type that can be stored in a netCDF-3 file
This function performs the following dtype conversions:
int64 -> int32
float64 -> float32
bool -> int8
unicode -> string
Data is checked for equality, or equivalence (non-NaN values) with
`np.allclose` with the default keyword arguments.
r �U�floatz/could not safely cast array from dtype %s to %szutf-8)
�str�dtype�_nc3_dtype_coercionsZastype�allr Zallclose_or_equiv�
ValueError�kind�np�coreZdefchararray�encode)Zarrr Z new_dtypeZcast_arr� r �7/tmp/pip-build-5_djhm0z/xray/xarray/backends/netcdf3.py�coerce_nc3_dtype s
r c C s> |