
    	g                        d Z 	 ddlZ e eeej                  j                  d                  Zedk  r e	d      dZ
ddlmZmZ ddlZd	eeef   d
eeef   fdZded
efdZdeeef   d
efdZdedeeef   d
dfdZy#  dZ
ddlZY MxY w)z'
Utilities for writing Stan Json files
    N.)   r   r   zujson version too oldTF)AnyMappingdreturnc                 h    | j                         D ci c]  \  }}|t        |       c}}S c c}}w )N)itemsprocess_value)r   kvs      H/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/stanio/json.pyprocess_dictionaryr      s*    ,-GGI6DAqA}Q666s   .valc           
         | y t        | t              rt        |       S t        | t              r| j                  | j
                  gS t        | t              rt        |       S t        | t              r9t        t        t        dt        |       dz         t        t        |                   S t        | t              r| D cg c]  }t        |       c}S t        t!        |       dd      }d|v s	d|v sd|v rt#        j$                  |       }|j&                  j(                  dv r|j+                         S |j&                  j(                  dk(  rat#        j,                  t#        j.                  |j                        t#        j.                  |j
                        gd	
      j+                         S |j&                  j(                  dk(  r#|j1                  t              j+                         S t        |j+                               S | S c c}w )N   
__module__ numpyxarraypandasiufc)axisb)
isinstanceboolintcomplexrealimagdictr   tupleziprangelenmapr   listgetattrtypenp
asanyarraydtypekindtoliststackasarrayastype)r   ioriginal_module	numpy_vals       r   r   r      s   
{#t3x#w#((###t!#&&#uCaSA.M30GHII#t*-.Qa ..d3ir:O?"&&MM#&	??5(##%%??3&88RZZ	7INN9ST[]^eegg??3&##C(//11 Y--/00J' /s   ?Hdatac                 >    t        j                  t        |             S )a4  
    Convert a mapping of strings to data to a JSON string.

    Values can be any numeric type, a boolean (converted to int),
    or any collection compatible with :func:`numpy.asarray`, e.g a
    :class:`pandas.Series`.

    Produces a string compatible with the
    `Json Format for Cmdstan
    <https://mc-stan.org/docs/cmdstan-guide/json.html>`__

    :param data: A mapping from strings to values. This can be a dictionary
        or something more exotic like an :class:`xarray.Dataset`. This will be
        copied before type conversion, not modified
    )jsondumpsr   )r7   s    r   dump_stan_jsonr;   ;   s      ::(.//    pathc                    t        | d      5 }t        r t        j                  t	        |      |       nBt        j
                         j                  t	        |            D ]  }|j                  |        ddd       y# 1 sw Y   yxY w)a  
    Dump a mapping of strings to data to a JSON file.

    Values can be any numeric type, a boolean (converted to int),
    or any collection compatible with :func:`numpy.asarray`, e.g a
    :class:`pandas.Series`.

    Produces a file compatible with the
    `Json Format for Cmdstan
    <https://mc-stan.org/docs/cmdstan-guide/json.html>`__

    :param path: File path for the created json. Will be overwritten if
        already in existence.

    :param data: A mapping from strings to values. This can be a dictionary
        or something more exotic like an :class:`xarray.Dataset`. This will be
        copied before type conversion, not modified
    wN)openUJSON_AVAILABLEr9   dumpr   JSONEncoder
iterencodewrite)r=   r7   fdchunks       r   write_stan_jsonrH   N   so    & 
dC  BII(.3))+667I$7OP   	     s   A)A??B)__doc__ujsonr9   r$   r(   r   __version__split
uj_versionImportErrorrA   typingr   r   r   r,   strr   r   r;   rH    r<   r   <module>rR      s   	s3 0 0 6 6s ;<=JI122O
   7'#s(+ 7S0A 7
s s D0c* 0s 0& #  WS#X%6  4  GOs   ;B B