
    hMhp                         d dl mZ d dlZd dlZdeej        eej        f         deej        eej        f         dej	        fdZ
ddej	        d	edefd
Zdej	        dej	        dej	        fdZdS )    )UnionNxyreturnc                     t          | t          j                  r| j        nd}t          |t          j                  r|j        nd}t          j        t          j        | |g          j        ||g          S )zConcat two array-like data structures into a DataFrame

    :param x: pd.Series, list or np.ndarray
    :param y: pd.Series, list or np.ndarray
    :return: pd.DataFrame
    r   r   )columns)
isinstancepdSeriesname	DataFramenparrayT)r   r   x_namey_names       J/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/phik/utils.pyarray_like_to_dataframer      sg     "!RY//8QVVSF!!RY//8QVVSF<!Q((*VV4DEEEE    Fdfverbosec                 $   |                      t          j        g          j                                        }|r1|r/t          d                    t          |                               t          |t                    st          d          |S )zSelect columns that have a dtype part of np.number

    :param df: DataFrame
    :param bool verbose: print all interval columns that are guessed
    :return: list of interval columns
    )includez&interval columns not set, guessing: {}z Could not guess interval columns)select_dtypesr   numberr   tolistprintformatstrr	   list
ValueError)r   r   interval_colss      r   guess_interval_colsr#      s     $$bi[$99AHHJJM S S6==c->P>PQQRRRmT** =;<<<r   observedexpectedc                 6   | j                                         }|j                                         }t          t          |          t          |          z
            }t          t          |          t          |          z
            }| j                                        }|j                                        }t          t          |          t          |          z
            }t          t          |          t          |          z
            }	|D ]}
d| |
<   |D ]}
d||
<   t          | j                   | _         t          |j                   |_         t          | j                   t          |j                   k    sJ |D ]0}t          j        t          | j                             | j	        |<   1|	D ]0}t          j        t          |j                             |j	        |<   1t          | j                  t          |j                  k    sJ |S )aW  Make observed and expected (pandas) histograms equal in shape

    Sometimes expected histogram shape need filling / pruning to make its shape equal to observed. Give expected the
    same number of columns and rows. Needed for proper histogram comparison.

    :param pd.DataFrame observed: The observed contingency table. The table contains the observed number of occurrences in each cell.
    :param pd.DataFrame expected: The expected contingency table. The table contains the expected number of occurrences in each cell.
    :return: expected frequencies, having the same shape as observed
    g        )
r   r   r    setindexsortedlenr   zerosloc)r$   r%   o_colse_colso_cols_missinge_cols_missingo_idxe_idxo_idx_missinge_idx_missingcis               r   make_shapes_equalr7   &   s    $$&&F$$&&F#f++F344N#f++F344NN!!##EN!!##EUc%jj011MUc%jj011M     h.//Hh.//Hx  C(8$9$99999  : :(3x'7#8#899Q : :(3x'7#8#899Qx~#hn"5"55555Or   )F)typingr   pandasr
   numpyr   r   r    ndarrayr   r   boolr#   r7    r   r   <module>r>      s                 FRYbj()F.3BItRZ4O.PF\F F F F BL 4 D     ' ' ' ' ' ' ' ' 'r   