U
    Cvfp  ã                   @  sH   d dl mZ d dlZd dlZd dlmZ d dlmZ G dd„ deƒZ	dS )é    )ÚannotationsN)ÚAbstractWritableDataStore)ÚVariablec                   @  sL   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	ddd„Z
dS )ÚInMemoryDataStorezÍ
    Stores dimensions, variables and attributes in ordered dictionaries, making
    this store fast compared to stores which save to disk.

    This store exists purely for internal testing purposes.
    Nc                 C  s(   |d kri n|| _ |d kri n|| _d S ©N)Ú
_variablesÚ_attributes)ÚselfÚ	variablesÚ
attributes© r   ú:/tmp/pip-unpacked-wheel-h316xyqg/xarray/backends/memory.pyÚ__init__   s    zInMemoryDataStore.__init__c                 C  s   | j S r   )r   ©r	   r   r   r   Ú	get_attrs   s    zInMemoryDataStore.get_attrsc                 C  s   | j S r   )r   r   r   r   r   Úget_variables   s    zInMemoryDataStore.get_variablesc                 C  s4   i }| j  ¡ D ] }|j ¡ D ]\}}|||< qq|S r   )r   ÚvaluesÚdimsÚitems)r	   r   ÚvÚdÚsr   r   r   Úget_dimensions   s
    z InMemoryDataStore.get_dimensionsc                 O  s*   t |jt |¡|jƒ}|| j|< ||jfS r   )r   r   ÚnpZ
empty_likeÚattrsr   Údata)r	   Úkr   ÚargsÚkwargsZnew_varr   r   r   Úprepare_variable$   s    
z"InMemoryDataStore.prepare_variablec                 C  s   t  |¡| j|< d S r   )ÚcopyÚdeepcopyr   )r	   r   r   r   r   r   Úset_attribute)   s    zInMemoryDataStore.set_attributec                 C  s   d S r   r   )r	   ZdimÚlengthZunlimited_dimsr   r   r   Úset_dimension-   s    zInMemoryDataStore.set_dimension)NN)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r"   r$   r   r   r   r   r      s   
r   )
Ú
__future__r   r    Znumpyr   Zxarray.backends.commonr   Zxarray.core.variabler   r   r   r   r   r   Ú<module>   s
   