py2ls 0.1.8.6__py3-none-any.whl → 0.1.8.7__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
@@ -362,6 +362,10 @@ def catplot(data, *args, **kwargs):
362
362
  "xticklabels": xticklabels,
363
363
  "xangle": xangle,
364
364
  }
365
+ else:
366
+ xticks = np.arange(1, data.shape[1] + 1)
367
+ default_x_width = 0.5
368
+ xangle = 0
365
369
 
366
370
  # full_order
367
371
  opt = kwargs.get("opt", {})
@@ -1450,30 +1454,49 @@ def padcat(*args, fill_value=np.nan, axis=1, order="row"):
1450
1454
  The value to use for padding the shorter lists (default is np.nan).
1451
1455
  axis : int, optional
1452
1456
  The axis along which to concatenate (0 for rows, 1 for columns, default is 1).
1457
+ order : str, optional
1458
+ The order for flattening when required: "row" or "column" (default is "row").
1453
1459
 
1454
1460
  Returns:
1455
1461
  np.ndarray
1456
1462
  A 2D array with the input arrays concatenated along the specified axis,
1457
1463
  padded with fill_value where necessary.
1458
1464
  """
1459
- # Convert all inputs to 1D NumPy arrays
1465
+ # Set the order for processing
1460
1466
  if "ro" in order.lower():
1461
- order = "C" # in row
1467
+ order = "C" # row-major order
1462
1468
  else:
1463
- order = "F" # column
1464
- arrays = [np.asarray(arg).flatten(order=order) for arg in args]
1469
+ order = "F" # column-major order
1470
+
1471
+ # Process input arrays based on their dimensions
1472
+ processed_arrays = []
1473
+ for arg in args:
1474
+ arr = np.asarray(arg)
1475
+ if arr.ndim == 1:
1476
+ processed_arrays.append(arr) # Keep 1D arrays as is
1477
+ elif arr.ndim == 2:
1478
+ if axis == 0:
1479
+ # If concatenating along rows, split 2D arrays into 1D arrays row-wise
1480
+ processed_arrays.extend(arr)
1481
+ elif axis == 1:
1482
+ # If concatenating along columns, split 2D arrays into 1D arrays column-wise
1483
+ processed_arrays.extend(arr.T)
1484
+ else:
1485
+ raise ValueError("axis must be 0 or 1")
1486
+ else:
1487
+ raise ValueError("Input arrays must be 1D or 2D")
1465
1488
 
1466
1489
  if axis == 0:
1467
1490
  # Concatenate along rows
1468
- max_len = max(arr.size for arr in arrays)
1469
- result = np.full((len(arrays), max_len), fill_value)
1470
- for i, arr in enumerate(arrays):
1491
+ max_len = max(arr.size for arr in processed_arrays)
1492
+ result = np.full((len(processed_arrays), max_len), fill_value)
1493
+ for i, arr in enumerate(processed_arrays):
1471
1494
  result[i, : arr.size] = arr
1472
1495
  elif axis == 1:
1473
1496
  # Concatenate along columns
1474
- max_len = max(arr.size for arr in arrays)
1475
- result = np.full((max_len, len(arrays)), fill_value)
1476
- for i, arr in enumerate(arrays):
1497
+ max_len = max(arr.size for arr in processed_arrays)
1498
+ result = np.full((max_len, len(processed_arrays)), fill_value)
1499
+ for i, arr in enumerate(processed_arrays):
1477
1500
  result[: arr.size, i] = arr
1478
1501
  else:
1479
1502
  raise ValueError("axis must be 0 or 1")
@@ -1481,6 +1504,17 @@ def padcat(*args, fill_value=np.nan, axis=1, order="row"):
1481
1504
  return result
1482
1505
 
1483
1506
 
1507
+ # # Example usage:
1508
+ # a = [1, np.nan]
1509
+ # b = [1, 3, 4, np.nan, 2, np.nan]
1510
+ # c = [1, 2, 3, 4, 5, 6, 7, 8, 10]
1511
+ # d = padcat(a, b)
1512
+ # result1 = padcat(d, c)
1513
+ # result2 = padcat(a, b, c)
1514
+ # print("Result of padcat(d, c):\n", result1)
1515
+ # print("Result of padcat(a, b, c):\n", result2)
1516
+
1517
+
1484
1518
  def sort_rows_move_nan(arr):
1485
1519
  # Handle edge cases where all values are NaN
1486
1520
  if np.all(np.isnan(arr)):
@@ -1507,23 +1541,30 @@ def sort_rows_move_nan(arr):
1507
1541
  return clean_arr_
1508
1542
 
1509
1543
 
1510
- def df2array(data: pd.DataFrame, x, y, hue=None):
1544
+ def df2array(data: pd.DataFrame, x, y, hue=None, sort=False):
1511
1545
  if hue is None:
1512
1546
  a = []
1513
- cat_x = data[x].unique().tolist()
1547
+ if sort:
1548
+ np.sort(data[x].unique().tolist()).tolist()
1549
+ else:
1550
+ cat_x = data[x].unique().tolist()
1514
1551
  for i, x_ in enumerate(cat_x):
1515
1552
  new_ = data.loc[data[x] == x_, y].to_list()
1516
- a = padcat(a, new_, axis=0)
1517
- return sort_rows_move_nan(a.reshape(2**i, -1))
1553
+ a = padcat(a, new_, axis=0).T
1554
+ return sort_rows_move_nan(a)
1518
1555
  else:
1519
1556
  a = []
1520
- cat_x = data[x].unique().tolist()
1521
- cat_hue = data[hue].unique().tolist()
1557
+ if sort:
1558
+ cat_x = np.sort(data[x].unique().tolist()).tolist()
1559
+ cat_hue = np.sort(data[hue].unique().tolist()).tolist()
1560
+ else:
1561
+ cat_x = data[x].unique().tolist()
1562
+ cat_hue = data[hue].unique().tolist()
1522
1563
  for i, x_ in enumerate(cat_x):
1523
1564
  for j, hue_ in enumerate(cat_hue):
1524
1565
  new_ = data.loc[(data[x] == x_) & (data[hue] == hue_), y].to_list()
1525
1566
  a = padcat(a, new_, axis=0)
1526
- return sort_rows_move_nan(a.reshape(2 ** ((i + 1) * (j + 1)), -1))
1567
+ return sort_rows_move_nan(a)
1527
1568
 
1528
1569
 
1529
1570
  def generate_xticks_with_gap(x_len, hue_len):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2ls
3
- Version: 0.1.8.6
3
+ Version: 0.1.8.7
4
4
  Summary: py(thon)2(too)ls
5
5
  Author: Jianfeng
6
6
  Author-email: Jianfeng.Liu0413@gmail.com
@@ -136,12 +136,12 @@ py2ls/export_requirements.py,sha256=x2WgUF0jYKz9GfA1MVKN-MdsM-oQ8yUeC6Ua8oCymio,
136
136
  py2ls/freqanalysis.py,sha256=F4218VSPbgL5tnngh6xNCYuNnfR-F_QjECUUxrPYZss,32594
137
137
  py2ls/ips.py,sha256=6eNvNwaCDj2jyjter7VPL9oEGB2jS4ge9mSgiIrvZfo,100788
138
138
  py2ls/netfinder.py,sha256=OMStrwMAASf1ajlyEfseoaEygo7G5WKBAFRE0LY15Lw,49477
139
- py2ls/plot.py,sha256=drlrWMUseSqkaTQHeTygypn39SUiovYuvThLQZ1Df_Y,55682
139
+ py2ls/plot.py,sha256=a0-U-NE31dEhiD-aBNWRIL81sBKfCIqeJeaefu-FpVE,57128
140
140
  py2ls/setuptools-70.1.0-py3-none-any.whl,sha256=2bi3cUVal8ip86s0SOvgspteEF8SKLukECi-EWmFomc,882588
141
141
  py2ls/sleep_events_detectors.py,sha256=bQA3HJqv5qnYKJJEIhCyhlDtkXQfIzqksnD0YRXso68,52145
142
142
  py2ls/stats.py,sha256=Wd9yCKQ_61QD29WMEgMuEcreFxF91NmlPW65iWT2B5w,39041
143
143
  py2ls/translator.py,sha256=bc5FB-wqC4TtQz9gyCP1mE38HqNRJ_pmuRIgKnAlMzM,30581
144
144
  py2ls/wb_detector.py,sha256=7y6TmBUj9exCZeIgBAJ_9hwuhkDh1x_-yg4dvNY1_GQ,6284
145
- py2ls-0.1.8.6.dist-info/METADATA,sha256=CCDGfjYmrUoLuYqvwidE8OkCBWs-EvCa5tviSzKVOjs,20017
146
- py2ls-0.1.8.6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
147
- py2ls-0.1.8.6.dist-info/RECORD,,
145
+ py2ls-0.1.8.7.dist-info/METADATA,sha256=yBv9UvJ5xZzrjdmCzBxhOuqIU3jAK1_StxP3ofxNtoE,20017
146
+ py2ls-0.1.8.7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
147
+ py2ls-0.1.8.7.dist-info/RECORD,,