← Back
Editing: records.cpython-311.pyc
� ���c�� � �" � d Z ddlZddlmZ ddlmZ ddlmZ ddlm Z ddlmZ dd l mZ dd lmZ g d�Zej Zdd ddd ddddd ddddd�Ze j Zd� Z ed� � G d� d� � � � Z G d� de j � � Z G d� de� � Zd� Z ed� � d$d�� � Z ed� � d$d�� � Z ed� � d%d�� � Zd � Z ed� � d%d!�� � Z ed� � d&d#�� � Z!dS )'a� Record Arrays ============= Record arrays expose the fields of structured arrays as properties. Most commonly, ndarrays contain elements of a single type, e.g. floats, integers, bools etc. However, it is possible for elements to be combinations of these using structured types, such as:: >>> a = np.array([(1, 2.0), (1, 2.0)], dtype=[('x', np.int64), ('y', np.float64)]) >>> a array([(1, 2.), (1, 2.)], dtype=[('x', '<i8'), ('y', '<f8')]) Here, each element consists of two fields: x (and int), and y (a float). This is known as a structured array. The different fields are analogous to columns in a spread-sheet. The different fields can be accessed as one would a dictionary:: >>> a['x'] array([1, 1]) >>> a['y'] array([2., 2.]) Record arrays allow us to access fields as properties:: >>> ar = np.rec.array(a) >>> ar.x array([1, 1]) >>> ar.y array([2., 2.]) � N)�Counter)�nullcontext� )�numeric)�numerictypes)� os_fspath)� set_module)�_get_legacy_print_mode)�record�recarray� format_parser� fromarrays�fromrecords� fromstring�fromfile�array�>�<�=�s�|)�b�l�n�B�L�N�Sr r r r r �I�ic �X � d� t | � � � � � D � � S )z@Find duplication in a list, return a list of duplicated elementsc �$ � g | ] \ }}|d k �|��S �r � )�.0�item�countss �4/usr/lib/python3/dist-packages/numpy/core/records.py� <listcomp>z"find_duplicate.<locals>.<listcomp>P s- � � � � ��D�&��A�:�:� ��:�:� )r �items)�lists r( �find_duplicater- N s5 � �� �#�D�M�M�/�/�1�1�� � � r* �numpyc �. � e Zd ZdZdd�Zd d�Zd� Zd� ZdS ) r a� Class to convert formats, names, titles description to a dtype. After constructing the format_parser object, the dtype attribute is the converted data-type: ``dtype = format_parser(formats, names, titles).dtype`` Attributes ---------- dtype : dtype The converted data-type. Parameters ---------- formats : str or list of str The format description, either specified as a string with comma-separated format descriptions in the form ``'f8, i4, a5'``, or a list of format description strings in the form ``['f8', 'i4', 'a5']``. names : str or list/tuple of str The field names, either specified as a comma-separated string in the form ``'col1, col2, col3'``, or as a list or tuple of strings in the form ``['col1', 'col2', 'col3']``. An empty list can be used, in that case default field names ('f0', 'f1', ...) are used. titles : sequence Sequence of title strings. An empty list can be used to leave titles out. aligned : bool, optional If True, align the fields by padding as the C-compiler would. Default is False. byteorder : str, optional If specified, all the fields will be changed to the provided byte-order. Otherwise, the default byte-order is used. For all available string specifiers, see `dtype.newbyteorder`. See Also -------- dtype, typename, sctype2char Examples -------- >>> np.format_parser(['<f8', '<i4', '<a5'], ['col1', 'col2', 'col3'], ... ['T1', 'T2', 'T3']).dtype dtype([(('T1', 'col1'), '<f8'), (('T2', 'col2'), '<i4'), (('T3', 'col3'), 'S5')]) `names` and/or `titles` can be empty lists. If `titles` is an empty list, titles will simply not appear. If `names` is empty, default field names will be used. >>> np.format_parser(['f8', 'i4', 'a5'], ['col1', 'col2', 'col3'], ... []).dtype dtype([('col1', '<f8'), ('col2', '<i4'), ('col3', '<S5')]) >>> np.format_parser(['<f8', '<i4', '<a5'], [], []).dtype dtype([('f0', '<f8'), ('f1', '<i4'), ('f2', 'S5')]) FNc � � | � ||� � | � ||� � | � |� � d S �N)� _parseFormats�_setfieldnames�_createdtype)�self�formats�names�titles�aligned� byteorders r( �__init__zformat_parser.__init__� sH � ����7�G�,�,�,����E�6�*�*�*����)�$�$�$�$�$r* c � �� |�t d� � �t |t � � r-t j d� t |� � D � � |� � }nt j ||� � }|j ���t j d|fg|� � }|j �|j }�fd�|D � � | _ �fd�|D � � | _ t |� � | _ dS )z Parse the field formats NzNeed formats argumentc �B � g | ]\ }}d � |� � |f��S )zf{})�format)r% r �format_s r( r) z/format_parser._parseFormats.<locals>.<listcomp>� s+ � �Q�Q�Q� ��7�%�,�,�q�/�/�7�+�Q�Q�Qr* �f1c �, �� g | ]}�| d ��S �r r$ �r% �key�fieldss �r( r) z/format_parser._parseFormats.<locals>.<listcomp>� s! �� �:�:�:�c�6�#�;�q�>�:�:�:r* c �, �� g | ]}�| d ��S r# r$ rC s �r( r) z/format_parser._parseFormats.<locals>.<listcomp>� s! �� �8�8�8�C����Q��8�8�8r* )� ValueError� isinstancer, �sb�dtype� enumeraterE r7 � _f_formats�_offsets�len�_nfields)r5 r6 r9 rJ �keysrE s @r( r2 zformat_parser._parseFormats� s� �� � �?��4�5�5�5��g�t�$�$� /��H�Q�Q�i��>P�>P�Q�Q�Q��� �E�E� �H�W�g�.�.�E�����>��H�t�U�m�_�g�6�6�E��\�F��{��:�:�:�:�T�:�:�:���8�8�8�8�4�8�8�8�� ��D� � �� � � r* c �� � |r�t |� � t t fv rnJt |t � � r|� d� � }nt dt |� � z � � �d� |d| j � D � � | _ ng | _ | xj d� t t | j � � | j � � D � � z c_ t | j � � }|rt d|z � � �|rd� |d| j � D � � | _ n g | _ g }| j t |� � k r+| xj dg| j t |� � z z z c_ dS dS )zQconvert input field names into a list and assign to the _names attribute �,zillegal input names %sc �6 � g | ]}|� � � ��S r$ ��strip�r% r s r( r) z0format_parser._setfieldnames.<locals>.<listcomp>� s � �D�D�D��1�7�7�9�9�D�D�Dr* Nc � � g | ]}d |z ��S )zf%dr$ )r% r s r( r) z0format_parser._setfieldnames.<locals>.<listcomp>� s. � � A� A� A�a��� � A� A� Ar* zDuplicate field names: %sc �6 � g | ]}|� � � ��S r$ rT rV s r( r) z0format_parser._setfieldnames.<locals>.<listcomp>� s � �F�F�F�!�A�G�G�I�I�F�F�Fr* )�typer, �tuplerH �str�split� NameError�reprrO �_names�rangerN r- rG �_titles)r5 r7 r8 �_dups r( r3 zformat_parser._setfieldnames� s� � � � ��E�{�{�t�U�m�+�+���E�3�'�'� H����C�(�(���� 8�4��;�;� F�G�G�G�D�D�e�N�T�]�N�.C�D�D�D�D�K�K��D�K� ��� A� A�5��T�[�1A�1A�15��,@� ,@� A� A� A� A��� �d�k�*�*��� A��8�4�?�@�@�@�� �F�F�v�n�t�}�n�/E�F�F�F�D�L�L��D�L��F��=�3�v�;�;�&�&��L�L�T�F�d�m�c�&�k�k�&A�B�B�L�L�L�L� '�&r* c �� � t j | j | j | j | j d�� � }|�(t |d }|� |� � }|| _ d S )N)r7 r6 �offsetsr8 r )rI rJ r_ rL rM ra �_byteorderconv�newbyteorder)r5 r: rJ s r( r4 zformat_parser._createdtype� se � ����[����}��l� � � � �� � �&�y��|�4�I��&�&�y�1�1�E��� � � r* )FN)F)�__name__� __module__�__qualname__�__doc__r; r2 r3 r4 r$ r* r( r r W si � � � � � �8� 8�t%� %� %� %� "� "� "� "�*"C� "C� "C�H� � � � r* r c �L � � e Zd ZdZd Z dZ� fd�Z� fd�Zd� Zd� Zd� Zd� Z � xZ S ) r zEA data-type scalar that allows field access as attribute lookup. r. c � �� t � � dk r| � � � S t � � � � � S �N�q )r �__str__�super�__repr__�r5 � __class__s �r( rq zrecord.__repr__� s8 �� �!�#�#�s�*�*��<�<�>�>�!��w�w���!�!�!r* c � �� t � � dk r!t | � � � � � S t � � � � � S rm )r r[ r&