qutePandas 1.0.0__py3-none-any.whl → 1.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,71 @@
1
+ import pykx as kx
2
+ import pandas as pd
3
+ from ..utils import _ensure_q_table, _handle_return
4
+
5
+
6
+ def cast(df, col, dtype, return_type='q'):
7
+ """
8
+ Converts column to specified data type.
9
+
10
+ Parameters
11
+ ----------
12
+ df : pandas.DataFrame or pykx.Table
13
+ Input DataFrame.
14
+ col : str
15
+ Column name to cast.
16
+ dtype : str
17
+ Target data type ('i' for int, 'f' for float, 's' for symbol, etc.).
18
+ return_type : str, default 'q'
19
+ Desired return type ('p' or 'q').
20
+
21
+ Returns
22
+ -------
23
+ pandas.DataFrame or pykx.Table
24
+ DataFrame with column cast to new type.
25
+ """
26
+ try:
27
+ q_map = {
28
+ 'int64': 'j', 'int32': 'i', 'int': 'i', 'long': 'j',
29
+ 'float64': 'f', 'float32': 'e', 'float': 'f', 'real': 'e',
30
+ 'object': 's', 'string': 'C', 'str': 'C',
31
+ 'j': 'j', 'i': 'i', 'h': 'h', 'f': 'f', 'e': 'e', 's': 's', 'c': 'c'
32
+ }
33
+
34
+ q_type = q_map.get(dtype, dtype)
35
+ q_table = _ensure_q_table(df)
36
+
37
+ if len(q_type) != 1:
38
+ raise ValueError(f"Unsupported q cast type: {dtype}")
39
+
40
+ curr_type = kx.q(f'{{type x`{col}}}', q_table).py()
41
+ type_to_code = {
42
+ 'j': 7, 'i': 6, 'h': 5, 'f': 9, 'e': 8, 's': 11, 'c': 10, 'b': 1
43
+ }
44
+ target_code = type_to_code.get(q_type.lower())
45
+
46
+ if target_code is not None and abs(curr_type) == target_code:
47
+ return _handle_return(q_table, return_type)
48
+
49
+ is_parsing = curr_type in (0, 10)
50
+ q_char = q_type.upper() if is_parsing else q_type.lower()
51
+
52
+ if q_char.lower() == 's':
53
+ result = kx.q(
54
+ f'{{update {col}:`$ string {col} from x}}',
55
+ q_table
56
+ )
57
+ elif q_char in ('i', 'j'):
58
+ result = kx.q(
59
+ f'{{update {col}:"{q_char}"$(({col}>=0)*floor {col} + ({col}<0)*ceiling {col}) from x}}',
60
+ q_table
61
+ )
62
+ else:
63
+ result = kx.q(
64
+ f'{{update {col}:"{q_char}"${col} from x}}',
65
+ q_table
66
+ )
67
+
68
+ return _handle_return(result, return_type)
69
+
70
+ except Exception as e:
71
+ raise RuntimeError(f"Failed to cast column {col} to type {dtype}: {e}")
@@ -0,0 +1,53 @@
1
+ import pykx as kx
2
+ import pandas as pd
3
+ from ..utils import _ensure_q_table, _handle_return, _validate_columns
4
+
5
+
6
+ def drop_col(df, cols, return_type='q'):
7
+ """
8
+ Removes specified column(s) from the DataFrame.
9
+
10
+ Parameters
11
+ ----------
12
+ df : pandas.DataFrame or pykx.Table
13
+ Input DataFrame.
14
+ cols : list of str or str
15
+ Column names to drop.
16
+ return_type : str, default 'q'
17
+ Desired return type ('p' or 'q').
18
+
19
+ Returns
20
+ -------
21
+ pandas.DataFrame or pykx.Table
22
+ DataFrame with specified column(s) removed.
23
+ """
24
+ try:
25
+ q_table = _ensure_q_table(df)
26
+
27
+ if isinstance(cols, str):
28
+ cols = [cols]
29
+
30
+ if not isinstance(cols, (list, tuple)):
31
+ raise ValueError("cols must be a list of column names")
32
+
33
+ if not cols:
34
+ return _handle_return(q_table, return_type)
35
+
36
+ _validate_columns(q_table, cols)
37
+
38
+ all_cols = kx.q("cols", q_table).py()
39
+ if len(cols) == len(all_cols):
40
+ if return_type == 'p':
41
+ count = kx.q('count', q_table).py()
42
+ return pd.DataFrame(index=range(count))
43
+ else:
44
+ result = kx.q('(0#`)!()')
45
+ return result
46
+ else:
47
+ q_cols = kx.SymbolVector(cols)
48
+ result = kx.q('{[t;c] ![t;();0b;(),c]}', q_table, q_cols)
49
+
50
+ return _handle_return(result, return_type)
51
+
52
+ except Exception as e:
53
+ raise RuntimeError(f"Failed to drop columns {cols}: {e}")
@@ -0,0 +1,35 @@
1
+ import pykx as kx
2
+ import pandas as pd
3
+ from ..utils import _ensure_q_table, _handle_return
4
+
5
+
6
+ def rename(df, columns, return_type='q'):
7
+ """
8
+ Renames columns in the DataFrame.
9
+
10
+ Parameters
11
+ ----------
12
+ df : pandas.DataFrame or pykx.Table
13
+ Input DataFrame.
14
+ columns : dict
15
+ Dictionary mapping old column names to new column names.
16
+ return_type : str, default 'q'
17
+ Desired return type ('p' or 'q').
18
+
19
+ Returns
20
+ -------
21
+ pandas.DataFrame or pykx.Table
22
+ DataFrame with renamed columns.
23
+ """
24
+ try:
25
+ q_table = _ensure_q_table(df)
26
+
27
+ cols = kx.q("cols", q_table).py()
28
+ new_cols = [columns.get(c, c) for c in cols]
29
+ new_cols_str = "`" + "`".join(new_cols)
30
+
31
+ result = kx.q(f'{new_cols_str} xcol', q_table)
32
+ return _handle_return(result, return_type)
33
+ except Exception as e:
34
+ raise RuntimeError(f"Failed to rename columns: {e}")
35
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: qutePandas
3
- Version: 1.0.0
3
+ Version: 1.1.1
4
4
  Summary: A pandas-like library for kdb+/q using pykx
5
5
  Home-page: https://ishapatro.github.io/qutePandas/
6
6
  Author: Isha Patro
@@ -0,0 +1,35 @@
1
+ qutePandas/__init__.py,sha256=QbVhBW6oE6B-f5BqIx_TNme6rk-zhSKb2iqe0RWAcFE,3143
2
+ qutePandas/utils.py,sha256=X0GODOBxuAFOtjjFb6IGlzjDhhrkwH_6ErIMypiFhUM,1026
3
+ qutePandas/apply/__init__.py,sha256=tdjeqTQI6jH530lTmpd9dkUPese6B22uI2P4ATKoGzc,92
4
+ qutePandas/apply/apply.py,sha256=5Fa4I7_zkILk0TMJioWoAFh9kgrb-jVI4PMBcjIkWmQ,2465
5
+ qutePandas/apply/apply_col.py,sha256=h6nAsAXLIC4WcMD-amW3bXkaNEe30SgKEBfUr3eKTng,1597
6
+ qutePandas/cleaning/__init__.py,sha256=6tRzTPgCEumZ7c_TvsMit3pRxZhdzf1Pd4y23ozv_2k,204
7
+ qutePandas/cleaning/dropna.py,sha256=SGIPg8vk4PB1jtnH8hDComuMz8omdraJhOPzKTRiUgI,739
8
+ qutePandas/cleaning/dropna_col.py,sha256=hpR4BN-ZuYdz222aUlYKyrEA7QmYomAMqTK6ebVB0ro,831
9
+ qutePandas/cleaning/fillna.py,sha256=9PDZCM1hyLtxFkVfQz7NJu1xrjDSW-nPQU47hysfDTI,1689
10
+ qutePandas/cleaning/remove_duplicates.py,sha256=zf6TTbkuSh5S4ZCmgznPLl-erw-umVP7K0EqOyv9wUM,757
11
+ qutePandas/core/__init__.py,sha256=o8WuiBhI5jBqKXTL80kBTNcxZo1aO45dQx2Z6UwWg50,311
12
+ qutePandas/core/connection.py,sha256=CsBWI2jwIO1kNicA42AefmlRgVx5WqayCJPhHzJHhFc,4275
13
+ qutePandas/core/dataframe.py,sha256=ehfz8lMIV_Yj1f9bMpY25TH3EMbR02Dvji9lhGg395E,3209
14
+ qutePandas/core/display.py,sha256=ubSZM8yf0kARuiSXpUHJ0WmIt4syjkp-VuV2NAXbiGc,5058
15
+ qutePandas/grouping/__init__.py,sha256=GOBRAWDuh3PnKHEVDzmEqoG_GIfU4G6Gtk0aeSG92lE,116
16
+ qutePandas/grouping/groupby_avg.py,sha256=F8Gc6XdOKiWyNKOoDURgYeeIxIduzbds2mHCfxEtvw4,1129
17
+ qutePandas/grouping/groupby_sum.py,sha256=9XZ2tITeCMRtdnpwH2CpoQh3Y3NDC-ufwiDg6EQUJOA,1128
18
+ qutePandas/indexing/__init__.py,sha256=2MmNlO54FOdIaaPSzegum3QmeO-Ts8ya3xSCodQjTIo,45
19
+ qutePandas/indexing/iloc.py,sha256=g0LYKZAqdVk6Xz--RUdb-VtECnzFRET28qh6KL5SRgE,3117
20
+ qutePandas/indexing/loc.py,sha256=Xn_043CrKyJBTXhRUYWtU0ZF1yikIGxTI0gTJAYIEfA,1511
21
+ qutePandas/introspection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
+ qutePandas/introspection/dtypes.py,sha256=h3qImsu3JBuELp2zeIfwyOlFTsC513U_qSRNuYzeXWw,705
23
+ qutePandas/io/__init__.py,sha256=sX93I3DAXM_kT0g67Nlhj_tAlVhtQe9Tr4AbgbEle3c,92
24
+ qutePandas/io/from_csv.py,sha256=QQ1lfyXGljvuJ4aL_RRaX7loRgfQ524XvWtBo0fTIHc,671
25
+ qutePandas/io/to_csv.py,sha256=7VrLtEjIUT-gIBXCYhW5GnbiRR2HqAZK6OW8Gy0ZOLM,926
26
+ qutePandas/joining/__init__.py,sha256=INM7LAOy5KqMIUrJdRHt7-no7ODiHsyx4F68hRbddYs,45
27
+ qutePandas/joining/merge.py,sha256=q9-X7QC7omhobO27q2aUego557ewh5RxALzAP7Mgq2M,3854
28
+ qutePandas/transformation/__init__.py,sha256=ECPmFXZq-uh5ajkgAVQbdc8flVzrcwkhEqwiOqqDeag,123
29
+ qutePandas/transformation/cast.py,sha256=VD8D0gPs9GJX52bqu_LKt7BHU69Iv-scOq-E2Q_MGQU,2226
30
+ qutePandas/transformation/drop_col.py,sha256=4hdGjitDbYSfxj-4jo73NmTa2qKed-NjGj0jGBfiANY,1509
31
+ qutePandas/transformation/rename.py,sha256=MwWjbhaZCUdQgkObaMPIB8fUY240x_EdD41cwszCa4o,948
32
+ qutepandas-1.1.1.dist-info/METADATA,sha256=F9226k9uz3MbdZhGJrzEveD7stG-JZPMsghZ4-6ySNE,2540
33
+ qutepandas-1.1.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
34
+ qutepandas-1.1.1.dist-info/top_level.txt,sha256=O_6KkoxW8KjgZX5o7sYwYVb8XPtNBA7PRSTE08qda1k,11
35
+ qutepandas-1.1.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,6 +0,0 @@
1
- qutePandas/__init__.py,sha256=BO7UwZvxdpkHzCeXWasLf6mSVx-wOpaBNyXCDlEb_80,2012
2
- qutePandas/utils.py,sha256=X0GODOBxuAFOtjjFb6IGlzjDhhrkwH_6ErIMypiFhUM,1026
3
- qutepandas-1.0.0.dist-info/METADATA,sha256=x6JQlnuk6MwcDaLy7SkkWu1YcC4TAml13Z4PWRE5l5c,2540
4
- qutepandas-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
- qutepandas-1.0.0.dist-info/top_level.txt,sha256=O_6KkoxW8KjgZX5o7sYwYVb8XPtNBA7PRSTE08qda1k,11
6
- qutepandas-1.0.0.dist-info/RECORD,,