HOME


sh-3ll 1.0
DIR:/usr/local/lib/python3.6/site-packages/xarray/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.6/site-packages/xarray/test/__pycache__/test_conventions.cpython-36.pyc
3

���h:f�@sTddlZddlZddlZddlZddlmZmZm	Z	m
Z
ddlmZm
Z
ddlmZmZmZddlmZddlmZddlmZdd	lmZdd
lmZGdd�de�ZGd
d�de�Zejdd��ZGdd�de�Z Gdd�de�Z!eGdd�de��Z"eGdd�de��Z#Gdd�dee�Z$Gdd�dej%�Z&dd�Z'eGdd �d ee��Z(dS)!�N)�conventions�Variable�Dataset�open_dataset)�utils�indexing�)�TestCase�requires_netCDF4�unittest)�CFEncodedDataTest)�	iteritems)�InMemoryDataStore)�WritableCFDataStore)�	decode_cfc@s$eZdZdd�Zdd�Zdd�ZdS)�TestMaskedAndScaledArraycCstjtjd�dd�}|j|jtjd��|j|jd�|j|jd�|j|jd�|jt	|�d�|j
tjddg|�tjtjd�dd�}|j
tjd�d|�tjtjd�dd�}|j
dtjd�|�tjtjdddddg�dd
d�}tjtjdddd
g�}|j
||�dS)N�r)�
fill_value�floatr�)�
add_offset)Zscale_factor�cg{�G�z�?g�G�z��?g)\��(�?gR���Q�?)ri�������i����)
r�MaskedAndScaledArray�np�arange�assertEqual�dtype�shape�size�ndim�len�assertArrayEqual�nan�array)�self�x�expected�r(�</tmp/pip-build-5_djhm0z/xray/xarray/test/test_conventions.py�tests
zTestMaskedAndScaledArray.testcCs`tjtjd�dd�}|jtj|��|jtj|d��tjtjd�dd�}|jd|d�dS)Nr)r.�
)rrrr$�
assertTrue�isnanr)r%r&r(r(r)�test_0d%s
z TestMaskedAndScaledArray.test_0dcCs|tjtjd�tjddg�d�}|jtjtjddg|�tjtjd�tjddg�d�}|jtj|��|jtj|d��dS)N�rr)rrr.)	rrrrr$r"r#r,r-)r%r&r(r(r)�test_multiple_fill_value-sz1TestMaskedAndScaledArray.test_multiple_fill_valueN)�__name__�
__module__�__qualname__r*r.r0r(r(r(r)rsrc@s$eZdZdd�Zdd�Zdd�ZdS)�TestCharToStringArraycCs�tjtd�dd�}tj|�}tjddd�}|j|j|j�|j|j|j�|j|j|j�|j|j	|j	�|j
t��t|�WdQRX|j
||�|j
t��|dd�WdQRX|jt|�d�tjtd�td�gdd�}tj|�}tjddgdd�}|j|j|j�|j|j|j�|j|j|j�|j|j	|j	�|jt|�t|��|j
||�|j
|dd�|dd��|j
t��|dd�dd�fWdQRXdS)N�abc�S)rrZcdfr)rr$�listrZCharToStringArrayrrrrr �assertRaises�	TypeErrorr!r"�
IndexError�str)r%r$�actualr'r(r(r)�test_wrapper_class9s2

z(TestCharToStringArray.test_wrapper_classcCsjtjdddgdddgg�}tjddg�}tj|�}|j||�tjd	d
dg�}tj|j�}|j||�dS)N�a�b�c�d�e�fr5�def�ad�beZcf)rr$rZchar_to_stringr"�T)r%r$r'r<r(r(r)�test_char_to_stringUs
z)TestCharToStringArray.test_char_to_stringcCs�tjddgddgg�}tjddgddggd	d
gddggg�}tj|�}|j||�tjddgd	d
ggddgddggg�}tj|j�}|j||�dS)
N�abZcdZefZghr>r?r@rArBrC�g�h)rr$rZstring_to_charr"rG)r%r$r'r<r(r(r)�test_string_to_char_s
z)TestCharToStringArray.test_string_to_charN)r1r2r3r=rHrLr(r(r(r)r48s
r4cCst|d�r|jdd�S|SdS)N�tzinfo)rM)�hasattr�replace)�dtr(r(r)�_ensure_naive_tzls
rQc@s�eZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zedd��Z	ed
d��Z
edd��Zedd��Zedd��Z
edd��Zdd�Zdd�Zdd�Zdd�Zdd �Zed!d"��Zd#S)$�TestDatetimec
Cs
ddl}�x�tjd�dftjd�jdd�dfdtjd�dfdtjd�dfdtjd�d	fdtjd�d
fd!dgdfdggdfddgdftjd�dfd"dgdfdggdftjd�dftjdd
d�dfd#ddgdfd$d%gD�]&\}}�xd&D�]}t|j|||��}t|||�tj	�� tj
dd�tj|||�}WdQRXt
|tj��rjtj|jtj��rj|jd�}n|}|j||�tj|||�\}}	}	d|k�r�|j|tj|d��t|d��r�|jdk�r�d |k�r�tjtj|�||�\}}	}	|j|tj|d���q�Wq�WdS)'Nrr+�days since 2000-01-01r�i0zhours since 1680-01-01 00:00:00zhour since 1680-01-01  00:00:00zHour  since 1680-01-01 00:00:00z" Hour  since  1680-01-01 00:00:00 zdaYs  since 2000-01-01�days since 1000-01-01i��i Nzdays since 1900-01-01��.MpA�hours since 1-1-1 00:00:0.0g�?g�?zhours since 1900-01-01T00:00:00�&milliseconds since 2000-01-01T00:00:00�&microseconds since 2000-01-01T00:00:00�standard�	gregorian�proleptic_gregorian�ignorezUnable to decode time axiszM8[us]z1-1-1rr Z1000)r+rS)rrU)rVrW)rrX)rrY)rZr[r\)�netCDF4rrZreshaper$rQ�num2date�print�warnings�catch_warnings�filterwarningsr�decode_cf_datetime�
isinstanceZndarrayZ
issubdtyperZ
datetime64Zastyper"Zencode_cf_datetimeZaroundrNr �pd�Index)
r%�nc4�	num_dates�units�calendarr'r<Z
actual_cmp�encoded�_r(r(r)�test_cf_datetimeusX






zTestDatetime.test_cf_datetimecCs�tjtjdddg�dd�}tjddd�j}|j|jtjd	��|j	||�tjtjdddg�d�}|j|jtjd	��|j	||�dS)
Nrrrzdays since 1900-01-01rZz
1900-01-01r)�periodszdatetime64[ns])
r�DecodedCFDatetimeArrayrr$rf�
date_range�valuesrrr")r%r<r'r(r(r)�test_decoded_cf_datetime_array�sz+TestDatetime.test_decoded_cf_datetime_arraycCs�tjtjdddg�dd�}tjddd�j}|j|jtjd	��|j	|t
dd�|t
dd��tjtjdddg�dd�}tjddd�j}|j|jtjd	��|j	|ddg|ddg�dS)
Nrrrzdays since 1900-01-01rZz
1900-01-01r)rozdatetime64[ns])rrprr$rfrqrrrrr"�slice)r%r<r'r(r(r)�$test_slice_decoded_cf_datetime_array�s z1TestDatetime.test_slice_decoded_cf_datetime_arraycCs6tjdddd�}d}tjtjd�|�}|j||�dS)N�dz
1970-01-01rK)ro�start�freqzhours since 1-1-1970)rfrqrrdrrr")r%r'rjr<r(r(r)�*test_decode_cf_datetime_non_standard_units�sz7TestDatetime.test_decode_cf_datetime_non_standard_unitscs6tdgtjd�dddd���|jtd�fdd	��dS)
N�tr+�foobarrr)rj�
missing_value�
_FillValuez_FillValue and missing_valuecs
tj��S)N)r�decode_cf_variabler()�varr(r)�<lambda>�szQTestDatetime.test_decode_cf_with_conflicting_fill_missing_value.<locals>.<lambda>)rrr�assertRaisesRegexp�
ValueError)r%r()rr)�2test_decode_cf_with_conflicting_fill_missing_value�s
z?TestDatetime.test_decode_cf_with_conflicting_fill_missing_valuecCsftjdddd�}tjd�dftjd�dftjd�dfg}x(|D] \}}tj||�}|j||�q>WdS)Nrvz
2000-01-01rK)rorwrxzhours since 2000-01-01 0zhours since 2000-1-1 0zhours since 2000-01-01 0:00)rfrqrrrrdr")r%r'Zcasesrirjr<r(r(r)�'test_decode_cf_datetime_non_iso_strings�sz4TestDatetime.test_decode_cf_datetime_non_iso_stringsc	
Cs�ddl}x�dD]�}d}tjd	d
dd�}|j|j�||d
�}|j}tj��"tjdd�t	j
|||d
�}WdQRX|j|jt
jd��t||�}|j|t
jdd�kj��qWdS)Nr�noleap�365_day�360_day�julian�all_leap�366_dayzdays since 0001-01-01z
2001-04-01-00z
2001-04-30-23�H)�endrx)rkr]zUnable to decode time axiszM8[ns]r�s)r�r�r�r�r�r�)r^rfrq�date2num�
to_pydatetimerrrarbrcrrdrrr�absr,�timedelta64�all)	r%rhrkrj�timesZnoleap_timer'r<Zabs_diffr(r(r)�!test_decode_non_standard_calendar�s 
z.TestDatetime.test_decode_non_standard_calendarcCstd}xjd
D]b}x\ddgdgggD]H}tj��"tjd	d
�tj|||d�}WdQRX|j|jtjd��q Wq
WdS)Nzdays since 0001-01-01r�r�r�r�r�r�i�8r]zUnable to decode time axis)rkzM8[ns])r�r�r�r�r�r�)rarbrcrrdrrr)r%rjrk�num_timer<r(r(r)�0test_decode_non_standard_calendar_single_elements
z=TestDatetime.test_decode_non_standard_calendar_single_elementc
Cs�ddl}d}|jjddd�}x�dD]z}|j|||�}|jd	��tj|||d
�}WdQRXtj|j	|||��}t
||||�|j|jtjd��|j||�q"WdS)
Nrzdays since 0001-01-01i�r�r�r�r�zUnable to decode time axis)rk�O)r�r�r�)
r^Z
netcdftime�datetimer��assertWarnsrrdrZasarrayr_r`rr)r%rhrjrPrkr�r<r'r(r(r)�9test_decode_non_standard_calendar_single_element_fallbacks
zFTestDatetime.test_decode_non_standard_calendar_single_element_fallbackcCsddl}d}d}tjdddd�}tjdd	dd�}|j|j�||d
�}|j|j�||d
�}tjt|�df�}||dd�df<||dd�df<|j}	|j}
t	j
��"t	jd
d�tj
|||d
�}WdQRX|j|jtjd��|j|dd�df|	�|j|dd�df|
�dS)Nrr�zdays since 0001-01-01z
2001-04-01z
2001-04-05�D)r�rxz
2001-05-01z
2001-05-05)rkrrr]zUnable to decode time axiszM8[ns])r^rfrqr�r�r�emptyr!rrrarbrcrrdrrr")r%rhrkrjZtimes1Ztimes2Znoleap_time1Znoleap_time2Z	mdim_timeZ	expected1Z	expected2r<r(r(r)�/test_decode_non_standard_calendar_multidim_times*
z<TestDatetime.test_decode_non_standard_calendar_multidim_timec	Cs�ddl}x�dD]�}x�dD]�}d}d
j|�}tjd�}|j|||�}tjdd
��F}tjd�tj	|||d�}|j
t|�d�|jdt
|dj��WdQRX|j
|jtjd��|j||�qWqWdS)Nr����������r�r�r�zdays since {0}-01-01rvT)�record�always)rkrzUnable to decode time axisr�)r�r�r�r�r�)r�r�r�)r^�formatrrr_rarb�simplefilterrrdrr!�assertInr;�messagerr")	r%rh�yearrkrjZ	num_timesr'�wr<r(r(r)�*test_decode_non_standard_calendar_fallback8s 




z7TestDatetime.test_decode_non_standard_calendar_fallbackcCs�x�tjgddgftjdgdddgftjddgddddgfgD]P\}}}tj��tjdd�tj||�}WdQRXtj|d	d
�}|j||�q<WdS)Nzdays since 2000-01-01�NaTrz2000-01-01T00:00:00Zrz2000-01-02T00:00:00Zr]zAll-NaNzdatetime64[ns])r)	rr#rarbrcrrdr$r")r%rirjZ
expected_listr<r'r(r(r)�test_cf_datetime_nanNs

z!TestDatetime.test_cf_datetime_nancCs�x�tjddd�dftjdddd�d	fdd
dgdftjdd
d
g�dftjddg�dftjd
dg�dftjd
g�dfgD]\}}|j|tj|��qtWdS)Nz
1900-01-01rT)rozdays since 1900-01-01 00:00:00z1900-01-01 12:00:00r�r)rxrozhours since 1900-01-01 12:00:00z
1900-01-02z1900-01-02 00:00:01z!seconds since 1900-01-01 00:00:00r�z1900-01-02T00:00:00.005zdays since 1970-01-01 00:00:00)rfrqZto_datetimerrZinfer_datetime_units)r%�datesr'r(r(r)�test_infer_datetime_units\s$
z&TestDatetime.test_infer_datetime_unitsc
Csxddtjd�fdddgdtjdddgd�fd	d
tjd�fddtjd�fd
dtjd�fdddgdtjddgfddgd
ddgfg}tjdkr�|jtjdd�dtjfddgdtjtjgfg�x�|D]�\}}}tj|dd�}tj|�}|}t	j
||�\}}|j||�|j|j
|j
�|dk	r�|}t	j||�}|j||�|j|j
|j
�q�Wtjdd�}t	jtjtj�d�}|j||�dS)NZ1D�daysrZ2DZ3Drr�int64�1h�hoursZ1msZmillisecondsZ1us�microsecondsr�Z0sZ1srZ30mZ60mg�?g�?z0.16�nsF)Zbox)rr�r$r#rf�__version__�extendr��to_timedeltarZencode_cf_timedeltar"rrZdecode_cf_timedelta)r%ZexamplesZ
timedeltasrjZnumbersr'r<rmr(r(r)�test_cf_timedeltaqs2

zTestDatetime.test_cf_timedeltacCslxftjddg�dftjddg�dftjddtjg�d	ftjd
dg�dfgD]\}}|j|tj|��qJWdS)
Nz1 dayz2 daysr�r�z1 day 1 hourr�Z1mZ2m�minutesZ1m3sZ1m4s�seconds)rfr�rr#rrZinfer_timedelta_units)r%Zdeltasr'r(r(r)�test_infer_timedelta_units�sz'TestDatetime.test_infer_timedelta_unitsc	Cs>tddddgddifi�}|jtd��t|�WdQRXdS)N�timerrrjzfoobar since 123zunable to decode time)rr�r�r)r%�dsr(r(r)�!test_invalid_units_raises_eagerly�sz.TestDatetime.test_invalid_units_raises_eagerlyc
Cs�ddd�}tj��<tjdd�ttddddg|fi��}|jd	t|��WdQRXd
di}ttddddg|fi��}|jdt|��dS)
Nzdays since 0001-01-01r�)rjrkr]zunable to decode timer�rrz
(time) objectrjzdays since 1900-01-01z(time) datetime64[ns])rarbrcrrr��repr)r%�attrsr�r(r(r)�(test_dataset_repr_with_netcdf4_datetimes�s

z5TestDatetime.test_dataset_repr_with_netcdf4_datetimesN)r1r2r3r
rnrsruryr�r�r�r�r�r�r�r�r�r�r�r�r�r(r(r(r)rRts"?


"rRc@seZdZdd�ZdS)�TestNativeEndiannessArraycCs^tjddd�}tjddd�}tj|�}|j|jks6t�|j|dd�jksNt�|j||�dS)NrTz>i8)rr�)rrrZNativeEndiannessArrayr�AssertionErrorr")r%r&r'r>r(r(r)r*�s
zTestNativeEndiannessArray.testN)r1r2r3r*r(r(r(r)r��sr�c@seZdZdd�Zdd�ZdS)�TestEncodeCFVariablec
Cs�tdgtjddd�ddi�tdgtjdg�ddi�tdgdd	d
gddidd
i�tdgdd	d
gddidd
i�g}x,|D]$}|jt��tj|�WdQRXqtWdS)
Nrzz
2000-01-01r)rorjr{z1 dayrrrrr})rrfrqr�r8r�r�encode_cf_variable)r%Zinvalid_varsrr(r(r)�test_incompatible_attributes�s 
z1TestEncodeCFVariable.test_incompatible_attributesc	CsJtdgtjtjdddg��}ddi|_|jd��tj|�WdQRXdS)Nr&rrrrZint16z!floating point data as an integer)rrr$r#�encodingr�rr�)r%�vr(r(r)�test_missing_fillvalue�s
z+TestEncodeCFVariable.test_missing_fillvalueN)r1r2r3r�r�r(r(r(r)r��sr�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestDecodeCFcCs�tddddgddifddddgddd	�fdd
ddgd
difd��}tdddddgddifitjddd�dddtjgfd��}tj|�}|j||�dS)Nrzrrrrjzdays since 2000-01-01�y�bar)�coordinatesrjrTr+i�r})rz�foor�r�z
2000-01-01r)rog@g$@)rzr�i���i���)rrfrqrr#rr�assertDatasetIdentical)r%�originalr'r<r(r(r)�test_dataset�s
zTestDecodeCF.test_datasetcCs4tddddgddifi�}tj|�}|j||�dS)Nr�rzrrr��invalid)rrrr�)r%r�r<r(r(r)�test_invalid_coordinates�s
z%TestDecodeCF.test_invalid_coordinatescCsFtdddgddifdddgfd��}tj|�}|j|jjdd�dS)	Nrzrrr�r&r/rT)r�r&)rrrrr�r�)r%r�r<r(r(r)�test_decode_coordinates�s
z$TestDecodeCF.test_decode_coordinatescCsBtftjd�ddid�}tftjd��}tj|�}|j||�dS)Nrrr�)r�)rrZint32r�rZmaybe_encode_dtyper�)r%r�r'r<r(r(r)�test_0d_int32_encoding�s
z#TestDecodeCF.test_0d_int32_encodingcCs�tdgdddgdtjddg�i�}tdgtjtjdgi�}tjdd��2}tj|�}|j||�|j	dt
|dj��WdQRXdS)	Nrzrrrr|T)r�zvariable has multiple fill)rrr$r#rarbrr~r�r�r;r�)r%r�r'r�r<r(r(r)�+test_decode_cf_with_multiple_missing_values�s
z8TestDecodeCF.test_decode_cf_with_multiple_missing_valuesc	Cs�tddddgddifddd	d
gddifddddgdddgdddggddifdd
ddgddifd��}ttjddd�ddddgfddddgdddgdddggddifdd
dtjgfd��}tj|dd�}tj|dd�}|j||�|j||�dS)Nrzrrrrjzdays since 2000-01-01r&�	���kmr�rTr+i�r})rzr&r�r�z
2000-01-01r)ro)Zdrop_variables)rzr&i���i���)rzr&)r&)rrfrqrr#rrr�)r%r�r'r<Zactual2r(r(r)�"test_decode_cf_with_drop_variables�s$$z/TestDecodeCF.test_decode_cf_with_drop_variablesN)	r1r2r3r�r�r�r�r�r�r(r(r(r)r��s	r�c@seZdZdS)�CFEncodedInMemoryStoreN)r1r2r3r(r(r(r)r�
sr�c@s eZdZdZdd�Zdd�ZdS)�NullWrapperzw
    Just for testing, this lets us create a numpy array directly
    but make it look like its not in memory yet.
    cCs
||_dS)N)r$)r%r$r(r(r)�__init__szNullWrapper.__init__cCs|jtj||j�S)N)r$rZorthogonal_indexerr)r%�keyr(r(r)�__getitem__szNullWrapper.__getitem__N)r1r2r3�__doc__r�r�r(r(r(r)r�sr�cCs$tdd�t|�D��}t||jd�S)zr
    Given a data store this wraps each variable in a NullWrapper so that
    it appears to be out of memory.
    css,|]$\}}|t|jt|j�|j�fVqdS)N)rZdimsr�rrr�)�.0�kr�r(r(r)�	<genexpr>sznull_wrap.<locals>.<genexpr>)�	variables�
attributes)�dictr
rr�)r�r�r(r(r)�	null_wrapsr�c@sFeZdZejdd��Zejiifdd��Zdd�Zdd�Zd	d
�Z	dS)�TestCFEncodedDataStoreccst�VdS)N)r�)r%r(r(r)�create_store&sz#TestCFEncodedDataStore.create_storeccs&t�}|j|f|�t|f|�VdS)N)r�Z
dump_to_storer)r%�dataZsave_kwargsZopen_kwargs�storer(r(r)�	roundtrip*sz TestCFEncodedDataStore.roundtripcCstjd��dS)Nz;cannot roundtrip coordinates yet for CFEncodedInMemoryStore)rZSkipTest)r%r(r(r)�test_roundtrip_coordinates0sz1TestCFEncodedDataStore.test_roundtrip_coordinatescCsdS)Nr()r%r(r(r)�"test_invalid_dataarray_names_raise4sz9TestCFEncodedDataStore.test_invalid_dataarray_names_raisecCsdS)Nr()r%r(r(r)�test_encoding_kwarg7sz*TestCFEncodedDataStore.test_encoding_kwargN)
r1r2r3�
contextlib�contextmanagerr�r�r�r�r�r(r(r(r)r�$sr�))r�ZnumpyrZpandasrfraZxarrayrrrrZxarray.corerr�r	r
rZ
test_backendsrZxarray.core.pycompatr
Zxarray.backends.memoryrZxarray.backends.commonrZxarray.conventionsrrr4Z	vectorizerQrRr�r�r�r�ZNDArrayMixinr�r�r�r(r(r(r)�<module>s6(4<
<