o
    5tin                     @   s4   d dl mZ d dlZddlmZ G dd deZdS )    )AnyN   )PythonCodeTableWriterc                       sd   e Zd ZdZdZedefddZdeddf fdd	Z	de
e fd
dZde
e fddZ  ZS )NumpyTableWritera  
    A table writer class for ``NumPy`` source code format.

        :Example:
            :ref:`example-numpy-table-writer`

    .. py:method:: write_table

        |write_table| with ``NumPy`` format.
        The tabular data are written as a variable definition of
        ``numpy.array``.

        :raises pytablewriter.EmptyTableNameError:
            If the |table_name| is empty.
        :Example:
            :ref:`example-numpy-table-writer`

        .. note::
            Specific values in the tabular data are converted when writing:

            - |None|: written as ``None``
            - |inf|: written as ``numpy.inf``
            - |nan|: written as ``numpy.nan``
            - |datetime| instances determined by |is_datetime_instance_formatting| attribute:
                - |True|: written as `dateutil.parser <https://dateutil.readthedocs.io/en/stable/parser.html>`__
                - |False|: written as |str|

            .. seealso::
                :ref:`example-type-hint-python`
    numpyreturnc                 C   s   | j S )N)FORMAT_NAMEself r   _/home/ubuntu/.local/lib/python3.10/site-packages/pytablewriter/writer/text/sourcecode/_numpy.pyformat_name*   s   zNumpyTableWriter.format_namekwargsNc                    sT   t  jdi | d| _| jtjj| jdd | jtjj| jdd d S )Nnpsz.infz.nanr   )	super__init__import_numpy_as_dp_extractorset_type_valuetypepyTypecodeINFINITYNAN)r
   r   	__class__r   r   r   .   s    zNumpyTableWriter.__init__c                 C   s2   | j dd}t| jr| j d| gS |gS )Nr   z.array([z = )r   r   is_not_null_string
table_namevariable_name)r
   	array_defr   r   r   _get_opening_row_items5   s   z'NumpyTableWriter._get_opening_row_itemsc                 C   s   dgS )Nz])r   r	   r   r   r   _get_closing_row_items=   s   z'NumpyTableWriter._get_closing_row_items)__name__
__module____qualname____doc__r   propertystrr   r   r   listr    r!   __classcell__r   r   r   r   r      s    r   )typingr   r   _pythonr   r   r   r   r   r   <module>   s    