py2ls 0.2.5.10__py3-none-any.whl → 0.2.5.14__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.
py2ls/plot.py CHANGED
@@ -23,6 +23,7 @@ from .ips import (
23
23
  get_df_format,
24
24
  df_corr,
25
25
  df_scaler,
26
+ df2array,array2df
26
27
  )
27
28
  import scipy.stats as scipy_stats
28
29
  from .stats import *
@@ -1350,7 +1351,7 @@ def catplot(data, *args, **kwargs):
1350
1351
  # # Example usage:
1351
1352
  # custom_order = ['s', 'bx', 'e']
1352
1353
  # full_order = sort_catplot_layers(custom_order)
1353
-
1354
+ data=data.copy()
1354
1355
  ax = kwargs.get("ax", None)
1355
1356
  col = kwargs.get("col", None)
1356
1357
  report = kwargs.get("report", True)
@@ -1363,8 +1364,9 @@ def catplot(data, *args, **kwargs):
1363
1364
  df = data.copy()
1364
1365
  x = kwargs.get("x", None)
1365
1366
  y = kwargs.get("y", None)
1366
- hue = kwargs.get("hue", None)
1367
+ hue = kwargs.get("hue", None)
1367
1368
  data = df2array(data=data, x=x, y=y, hue=hue)
1369
+
1368
1370
  y_max_loc = np.max(data, axis=0)
1369
1371
  xticklabels = []
1370
1372
  if hue is not None:
@@ -1518,7 +1520,11 @@ def catplot(data, *args, **kwargs):
1518
1520
  display_output(res)
1519
1521
 
1520
1522
  # when the xticklabels are too long, rotate the labels a bit
1521
- xangle = 30 if max([len(i) for i in xticklabels]) > 50 else 0
1523
+ try:
1524
+ xangle = 30 if max([len(i) for i in xticklabels]) > 50 else 0
1525
+ except:
1526
+ xangle = 0
1527
+
1522
1528
  if kw_figsets is not None:
1523
1529
  kw_figsets = {
1524
1530
  "ylabel": y,
@@ -3259,13 +3265,13 @@ def plot_xy(
3259
3265
  x=None,
3260
3266
  y=None,
3261
3267
  ax=None,
3262
- kind: Union[str, list] = None, # Specify the kind of plot
3268
+ kind_: Union[str, list] = None, # Specify the kind of plot
3263
3269
  verbose=False,
3264
3270
  **kwargs,
3265
3271
  ):
3266
3272
  # You can call the original plotxy function if needed
3267
3273
  # or simply replicate the functionality here
3268
- return plotxy(data, x, y, ax, kind, verbose, **kwargs)
3274
+ return plotxy(data, x=x, y=y, ax=ax, kind_=kind_, verbose=verbose, **kwargs)
3269
3275
 
3270
3276
 
3271
3277
  def plotxy(
@@ -3353,7 +3359,7 @@ def plotxy(
3353
3359
 
3354
3360
  # ============ preprocess data ============
3355
3361
  try:
3356
- data = df_preprocessing_(data, kind=kind_[0])
3362
+ data = df_preprocessing_(data, kind=kind_[0])
3357
3363
  if "variable" in data.columns and "value" in data.columns:
3358
3364
  x, y = "variable", "value"
3359
3365
  except Exception as e:
@@ -3903,7 +3909,7 @@ def df_preprocessing_(data, kind, verbose=False):
3903
3909
  "pointplot", # Works well with wide format
3904
3910
  "ellipse",
3905
3911
  ]
3906
-
3912
+ print(kind)
3907
3913
  # Wide format (e.g., for heatmap and pairplot)
3908
3914
  if kind in wide_kinds:
3909
3915
  if df_format_ != "wide":
py2ls/stats.py CHANGED
@@ -8,7 +8,7 @@ import matplotlib.pyplot as plt
8
8
  import warnings
9
9
 
10
10
  warnings.filterwarnings("ignore", category=RuntimeWarning)
11
-
11
+ from .ips import df2array
12
12
 
13
13
  # FuncStars --v 0.1.1
14
14
  def FuncStars(
@@ -902,148 +902,5 @@ def df_wide_long(df):
902
902
  return "Long"
903
903
 
904
904
 
905
- def sort_rows_move_nan(arr, sort=False):
906
- # Handle edge cases where all values are NaN
907
- if np.all(np.isnan(arr)):
908
- return arr # Return unchanged if the entire array is NaN
909
-
910
- if sort:
911
- # Replace NaNs with a temporary large value for sorting
912
- temp_value = (
913
- np.nanmax(arr[np.isfinite(arr)]) + 1 if np.any(np.isfinite(arr)) else np.inf
914
- )
915
- arr_no_nan = np.where(np.isnan(arr), temp_value, arr)
916
-
917
- # Sort each row
918
- sorted_arr = np.sort(arr_no_nan, axis=1)
919
-
920
- # Move NaNs to the end
921
- result_arr = np.where(sorted_arr == temp_value, np.nan, sorted_arr)
922
- else:
923
- result_rows = []
924
- for row in arr:
925
- # Separate non-NaN and NaN values
926
- non_nan_values = row[~np.isnan(row)]
927
- nan_count = np.isnan(row).sum()
928
- # Create a new row with non-NaN values followed by NaNs
929
- new_row = np.concatenate([non_nan_values, [np.nan] * nan_count])
930
- result_rows.append(new_row)
931
- # Convert the list of rows back into a 2D NumPy array
932
- result_arr = np.array(result_rows)
933
-
934
- # Remove rows/columns that contain only NaNs
935
- clean_arr = result_arr[~np.isnan(result_arr).all(axis=1)]
936
- clean_arr_ = clean_arr[:, ~np.isnan(clean_arr).all(axis=0)]
937
-
938
- return clean_arr_
939
-
940
-
941
- def df2array(data: pd.DataFrame, x=None, y=None, hue=None, sort=False):
942
- if hue is None:
943
- a = []
944
- if sort:
945
- cat_x = np.sort(data[x].unique().tolist()).tolist()
946
- else:
947
- cat_x = data[x].unique().tolist()
948
- for i, x_ in enumerate(cat_x):
949
- new_ = data.loc[data[x] == x_, y].to_list()
950
- a = padcat(a, new_, axis=0)
951
- return sort_rows_move_nan(a).T
952
- else:
953
- a = []
954
- if sort:
955
- cat_x = np.sort(data[x].unique().tolist()).tolist()
956
- cat_hue = np.sort(data[hue].unique().tolist()).tolist()
957
- else:
958
- cat_x = data[x].unique().tolist()
959
- cat_hue = data[hue].unique().tolist()
960
- for i, x_ in enumerate(cat_x):
961
- for j, hue_ in enumerate(cat_hue):
962
- new_ = data.loc[(data[x] == x_) & (data[hue] == hue_), y].to_list()
963
- a = padcat(a, new_, axis=0)
964
- return sort_rows_move_nan(a).T
965
-
966
-
967
- def array2df(data: np.ndarray):
968
- df = pd.DataFrame()
969
- df["group"] = (
970
- np.tile(
971
- ["group" + str(i) for i in range(1, data.shape[1] + 1)], [data.shape[0], 1]
972
- )
973
- .reshape(-1, 1, order="F")[:, 0]
974
- .tolist()
975
- )
976
- df["value"] = data.reshape(-1, 1, order="F")
977
- return df
978
-
979
-
980
- def padcat(*args, fill_value=np.nan, axis=1, order="row"):
981
- """
982
- Concatenate vectors with padding.
983
-
984
- Parameters:
985
- *args : variable number of list or 1D arrays
986
- Input arrays to concatenate.
987
- fill_value : scalar, optional
988
- The value to use for padding the shorter lists (default is np.nan).
989
- axis : int, optional
990
- The axis along which to concatenate (0 for rows, 1 for columns, default is 1).
991
- order : str, optional
992
- The order for flattening when required: "row" or "column" (default is "row").
993
-
994
- Returns:
995
- np.ndarray
996
- A 2D array with the input arrays concatenated along the specified axis,
997
- padded with fill_value where necessary.
998
- """
999
- # Set the order for processing
1000
- if "ro" in order.lower():
1001
- order = "C" # row-major order
1002
- else:
1003
- order = "F" # column-major order
1004
-
1005
- # Process input arrays based on their dimensions
1006
- processed_arrays = []
1007
- for arg in args:
1008
- arr = np.asarray(arg)
1009
- if arr.ndim == 1:
1010
- processed_arrays.append(arr) # Keep 1D arrays as is
1011
- elif arr.ndim == 2:
1012
- if axis == 0:
1013
- # If concatenating along rows, split 2D arrays into 1D arrays row-wise
1014
- processed_arrays.extend(arr)
1015
- elif axis == 1:
1016
- # If concatenating along columns, split 2D arrays into 1D arrays column-wise
1017
- processed_arrays.extend(arr.T)
1018
- else:
1019
- raise ValueError("axis must be 0 or 1")
1020
- else:
1021
- raise ValueError("Input arrays must be 1D or 2D")
1022
-
1023
- if axis == 0:
1024
- # Concatenate along rows
1025
- max_len = max(arr.size for arr in processed_arrays)
1026
- result = np.full((len(processed_arrays), max_len), fill_value)
1027
- for i, arr in enumerate(processed_arrays):
1028
- result[i, : arr.size] = arr
1029
- elif axis == 1:
1030
- # Concatenate along columns
1031
- max_len = max(arr.size for arr in processed_arrays)
1032
- result = np.full((max_len, len(processed_arrays)), fill_value)
1033
- for i, arr in enumerate(processed_arrays):
1034
- result[: arr.size, i] = arr
1035
- else:
1036
- raise ValueError("axis must be 0 or 1")
1037
-
1038
- return result
1039
905
 
1040
906
 
1041
- # # Example usage:
1042
- # a = [1, np.nan]
1043
- # b = [1, 3, 4, np.nan, 2, np.nan]
1044
- # c = [1, 2, 3, 4, 5, 6, 7, 8, 10]
1045
- # d = padcat(a, b)
1046
- # result1 = padcat(d, c)
1047
- # result2 = padcat(a, b, c)
1048
- # print("Result of padcat(d, c):\n", result1)
1049
- # print("Result of padcat(a, b, c):\n", result2)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2ls
3
- Version: 0.2.5.10
3
+ Version: 0.2.5.14
4
4
  Summary: py(thon)2(too)ls
5
5
  Author: Jianfeng
6
6
  Author-email: Jianfeng.Liu0413@gmail.com
@@ -18,7 +18,7 @@ py2ls/.git/hooks/pre-receive.sample,sha256=pMPSuce7P9jRRBwxvU7nGlldZrRPz0ndsxAlI
18
18
  py2ls/.git/hooks/prepare-commit-msg.sample,sha256=6d3KpBif3dJe2X_Ix4nsp7bKFjkLI5KuMnbwyOGqRhk,1492
19
19
  py2ls/.git/hooks/push-to-checkout.sample,sha256=pT0HQXmLKHxt16-mSu5HPzBeZdP0lGO7nXQI7DsSv18,2783
20
20
  py2ls/.git/hooks/update.sample,sha256=jV8vqD4QPPCLV-qmdSHfkZT0XL28s32lKtWGCXoU0QY,3650
21
- py2ls/.git/index,sha256=c1AO_wJSDaf38yBek-Wd6EH8sKYZD1HlMgI2rHQTKDk,4232
21
+ py2ls/.git/index,sha256=p_emoQrhXhCenpHHN8G7ox7DJvEZM0qvp4JBljVCJvM,4232
22
22
  py2ls/.git/info/exclude,sha256=ZnH-g7egfIky7okWTR8nk7IxgFjri5jcXAbuClo7DsE,240
23
23
  py2ls/.git/logs/HEAD,sha256=8ID7WuAe_TlO9g-ARxhIJYdgdL3u3m7-1qrOanaIUlA,3535
24
24
  py2ls/.git/logs/refs/heads/main,sha256=8ID7WuAe_TlO9g-ARxhIJYdgdL3u3m7-1qrOanaIUlA,3535
@@ -241,19 +241,21 @@ py2ls/ec2ls.py,sha256=PyLkiWYB8AJTIGdMn6VrEoE2vFtPYxt4WrCJfGQPFDk,2271
241
241
  py2ls/export_requirements.py,sha256=x2WgUF0jYKz9GfA1MVKN-MdsM-oQ8yUeC6Ua8oCymio,2325
242
242
  py2ls/fetch_update.py,sha256=9LXj661GpCEFII2wx_99aINYctDiHni6DOruDs_fdt8,4752
243
243
  py2ls/freqanalysis.py,sha256=F4218VSPbgL5tnngh6xNCYuNnfR-F_QjECUUxrPYZss,32594
244
- py2ls/ich2ls.py,sha256=3E9R8oVpyYZXH5PiIQgT3CN5NxLe4Dwtm2LwaeacE6I,21381
245
- py2ls/ips.py,sha256=FJdNHEvDLHmmGeRCq1NlNlgumik-Gv5796pw8wfJAG8,487017
244
+ py2ls/ich2ls.py,sha256=zXWdQzebBZjFIfpjgJuqZ6_7AnGehFTPX-BoNnAQwyc,81940
245
+ py2ls/im2.py,sha256=inSdpU_IIvHG7FoXcdIvpGprPASySwJCR05Lpaa5fdU,3026
246
+ py2ls/ips.py,sha256=UvEz8NOzvx8E5qsHuXhaU3tZLxI9m9_gDWrp9kt4uPc,689157
247
+ py2ls/ips_lab.py,sha256=WmZVIatIWcfvuVrM88lVXygI7fnonI8a_5NSTnF0rTg,666051
246
248
  py2ls/ml2ls.py,sha256=I-JFPdikgEtfQjhv5gBz-QSeorpTJI_Pda_JwkTioBY,209732
247
249
  py2ls/mol.py,sha256=AZnHzarIk_MjueKdChqn1V6e4tUle3X1NnHSFA6n3Nw,10645
248
- py2ls/netfinder.py,sha256=OhqD3S9PuwweL2013D-q4GNP1WvJjuYfZzq5BZgGddE,68980
250
+ py2ls/netfinder.py,sha256=GZinvZrKRV7h8GPPUBczFEcUKoHNLinh7PafnqMqsYg,81131
249
251
  py2ls/nl2ls.py,sha256=UEIdok-OamFZFIvvz_PdZenu085zteMdaJd9mLu3F-s,11485
250
252
  py2ls/ocr.py,sha256=WDFvx1oVxXjlyyFs2a6pizdu4-jEL5pTFLP960-HbyM,33939
251
- py2ls/plot.py,sha256=iE_T8G4Yv7QdnxVJH_zUsFOHL4zi9mga6FZhXpFb2XA,239505
253
+ py2ls/plot.py,sha256=zS6x4BKquSoNZSMmpHi9-kb3ceXtELvnBnwxylm0Z4U,239669
252
254
  py2ls/setuptools-70.1.0-py3-none-any.whl,sha256=2bi3cUVal8ip86s0SOvgspteEF8SKLukECi-EWmFomc,882588
253
255
  py2ls/sleep_events_detectors.py,sha256=bQA3HJqv5qnYKJJEIhCyhlDtkXQfIzqksnD0YRXso68,52145
254
- py2ls/stats.py,sha256=qBn2rJmNa_QLLUqjwYqXUlGzqmW94sgA1bxJU2FC3r0,39175
256
+ py2ls/stats.py,sha256=xBXUHgV92iqNKtNaj7p5YouNJXKPrJcwkYJhc6lw8NI,34107
255
257
  py2ls/translator.py,sha256=77Tp_GjmiiwFbEIJD_q3VYpQ43XL9ZeJo6Mhl44mvh8,34284
256
258
  py2ls/wb_detector.py,sha256=7y6TmBUj9exCZeIgBAJ_9hwuhkDh1x_-yg4dvNY1_GQ,6284
257
- py2ls-0.2.5.10.dist-info/METADATA,sha256=H8N6X7SCqvk7cgK2N7ZFXTnKqNMFZsmlfmaQ17wrTfk,20632
258
- py2ls-0.2.5.10.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
259
- py2ls-0.2.5.10.dist-info/RECORD,,
259
+ py2ls-0.2.5.14.dist-info/METADATA,sha256=K7E7Fjc9zBYCM7IjUY2KR8yosnz9K4CAriQkziE_foU,20632
260
+ py2ls-0.2.5.14.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
261
+ py2ls-0.2.5.14.dist-info/RECORD,,