py2ls 0.1.10.27__py3-none-any.whl → 0.2.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.
py2ls/ips.py CHANGED
@@ -1276,7 +1276,7 @@ def unzip(dir_path, output_dir=None):
1276
1276
  os.remove(output_dir) # remove file
1277
1277
 
1278
1278
  # Handle .tar.gz files
1279
- if dir_path.endswith(".tar.gz"):
1279
+ if dir_path.endswith(".tar.gz") or dir_path.endswith(".tgz"):
1280
1280
  import tarfile
1281
1281
 
1282
1282
  with tarfile.open(dir_path, "r:gz") as tar_ref:
@@ -1399,13 +1399,65 @@ def fload(fpath, kind=None, **kwargs):
1399
1399
  root = tree.getroot()
1400
1400
  return etree.tostring(root, pretty_print=True).decode()
1401
1401
 
1402
- def load_csv(fpath, engine="pyarrow", **kwargs):
1403
- print(f"engine={engine}")
1404
- df = pd.read_csv(fpath, engine=engine, **kwargs)
1402
+ def load_csv(fpath, **kwargs):
1403
+ engine = kwargs.get("engine", "pyarrow")
1404
+ kwargs.pop("engine", None)
1405
+ index_col = kwargs.get("index_col", None)
1406
+ kwargs.pop("index_col", None)
1407
+ memory_map = kwargs.get("memory_map", True)
1408
+ kwargs.pop("memory_map", None)
1409
+ skipinitialspace = kwargs.get("skipinitialspace", True)
1410
+ kwargs.pop("skipinitialspace", None)
1411
+ encoding = kwargs.get("encoding", "utf-8")
1412
+ kwargs.pop("encoding", None)
1413
+ try:
1414
+ if engine == "pyarrow":
1415
+ df = pd.read_csv(
1416
+ fpath,
1417
+ engine=engine,
1418
+ index_col=index_col,
1419
+ encoding=encoding,
1420
+ **kwargs,
1421
+ )
1422
+ else:
1423
+ df = pd.read_csv(
1424
+ fpath,
1425
+ engine=engine,
1426
+ index_col=index_col,
1427
+ memory_map=memory_map,
1428
+ encoding=encoding,
1429
+ skipinitialspace=skipinitialspace,
1430
+ **kwargs,
1431
+ )
1432
+ print("File loaded successfully with utf-8 encoding.")
1433
+ except UnicodeDecodeError:
1434
+ encoding = get_encoding(fpath)
1435
+ print(f"utf-8 failed. Retrying with detected encoding: {encoding}")
1436
+ if engine == "pyarrow":
1437
+ df = pd.read_csv(
1438
+ fpath,
1439
+ engine=engine,
1440
+ index_col=index_col,
1441
+ encoding=encoding,
1442
+ **kwargs,
1443
+ )
1444
+ else:
1445
+ df = pd.read_csv(
1446
+ fpath,
1447
+ engine=engine,
1448
+ index_col=index_col,
1449
+ memory_map=memory_map,
1450
+ encoding=encoding,
1451
+ skipinitialspace=skipinitialspace,
1452
+ **kwargs,
1453
+ )
1454
+ print("File loaded successfully with utf-8 encoding.")
1405
1455
  return df
1406
1456
 
1407
1457
  def load_xlsx(fpath, **kwargs):
1408
- df = pd.read_excel(fpath, **kwargs)
1458
+ engine = kwargs.get("engine", "openpyxl")
1459
+ kwargs.pop("engine", None)
1460
+ df = pd.read_excel(fpath, engine=engine, **kwargs)
1409
1461
  return df
1410
1462
 
1411
1463
  def load_ipynb(fpath, **kwargs):
@@ -1511,7 +1563,18 @@ def fload(fpath, kind=None, **kwargs):
1511
1563
  "pdf",
1512
1564
  "ipynb",
1513
1565
  ]
1514
- zip_types = ["gz", "zip", "7z", "tar", "tar.gz", "tar.bz2", "bz2", "xz", "rar"]
1566
+ zip_types = [
1567
+ "gz",
1568
+ "zip",
1569
+ "7z",
1570
+ "tar",
1571
+ "tar.gz",
1572
+ "tar.bz2",
1573
+ "bz2",
1574
+ "xz",
1575
+ "rar",
1576
+ "tgz",
1577
+ ]
1515
1578
  supported_types = [*doc_types, *img_types, *zip_types]
1516
1579
  if kind not in supported_types:
1517
1580
  print(f'Error:\n"{kind}" is not in the supported list {supported_types}')
@@ -1545,6 +1608,14 @@ def fload(fpath, kind=None, **kwargs):
1545
1608
  return load_xml(fpath)
1546
1609
  elif kind == "csv":
1547
1610
  return load_csv(fpath, **kwargs)
1611
+ elif kind in ["ods", "ods", "odt"]:
1612
+ engine = kwargs.get("engine", "odf")
1613
+ kwargs.pop("engine", None)
1614
+ return load_xlsx(fpath, engine=engine, **kwargs)
1615
+ elif kind == "xls":
1616
+ engine = kwargs.get("engine", "xlrd")
1617
+ kwargs.pop("engine", None)
1618
+ return load_xlsx(fpath, engine=engine, **kwargs)
1548
1619
  elif kind == "xlsx":
1549
1620
  return load_xlsx(fpath, **kwargs)
1550
1621
  elif kind == "ipynb":
@@ -1558,17 +1629,51 @@ def fload(fpath, kind=None, **kwargs):
1558
1629
  elif kind.lower() in zip_types:
1559
1630
  keep = kwargs.get("keep", False)
1560
1631
  fpath_unzip = unzip(fpath)
1561
- content_unzip = fload(fpath_unzip, **kwargs)
1562
- if not keep:
1563
- os.remove(fpath_unzip)
1564
- return content_unzip
1632
+ if os.path.isdir(fpath_unzip):
1633
+ print(f"{fpath_unzip} is a folder. fload stoped.")
1634
+ fpath_list = os.listdir("./datasets/GSE10927_family.xml")
1635
+ print(f"{len(fpath_list)} files within the folder")
1636
+ if len(fpath_list) > 5:
1637
+ pp(fpath_list[:5])
1638
+ print("there are more ...")
1639
+ else:
1640
+ pp(fpath_list)
1641
+ return fpath_list
1642
+ elif os.path.isfile(fpath_unzip):
1643
+ print(f"{fpath_unzip} is a file.")
1644
+ content_unzip = fload(fpath_unzip, **kwargs)
1645
+ if not keep:
1646
+ os.remove(fpath_unzip)
1647
+ return content_unzip
1648
+ else:
1649
+ print(f"{fpath_unzip} does not exist or is a different type.")
1650
+
1651
+ elif kind.lower() == "gmt":
1652
+ import gseapy as gp
1653
+
1654
+ gene_sets = gp.read_gmt(fpath)
1655
+ return gene_sets
1565
1656
  else:
1566
1657
  try:
1567
- with open(fpath, "r") as f:
1568
- content = f.readlines()
1658
+ try:
1659
+ with open(fpath, "r", encoding="utf-8") as f:
1660
+ content = f.readlines()
1661
+ except UnicodeDecodeError:
1662
+ print("Failed to read as utf-8, trying different encoding...")
1663
+ with open(
1664
+ fpath, "r", encoding=get_encoding(fpath)
1665
+ ) as f: # Trying with a different encoding
1666
+ content = f.readlines()
1569
1667
  except:
1570
- with open(fpath, "r") as f:
1571
- content = f.read()
1668
+ try:
1669
+ with open(fpath, "r", encoding="utf-8") as f:
1670
+ content = f.read()
1671
+ except UnicodeDecodeError:
1672
+ print("Failed to read as utf-8, trying different encoding...")
1673
+ with open(
1674
+ fpath, "r", encoding=get_encoding(fpath)
1675
+ ) as f: # Trying with a different encoding
1676
+ content = f.read()
1572
1677
  return content
1573
1678
 
1574
1679
 
@@ -4200,7 +4305,7 @@ def df_as_type(
4200
4305
  columns: Optional[Union[str, List[str]]] = None,
4201
4306
  astype: str = "datetime",
4202
4307
  format: Optional[str] = None,
4203
- inplace: bool = False,
4308
+ inplace: bool = True,
4204
4309
  errors: str = "coerce", # Can be "ignore", "raise", or "coerce"
4205
4310
  **kwargs,
4206
4311
  ) -> Optional[pd.DataFrame]:
@@ -4353,8 +4458,7 @@ def df_as_type(
4353
4458
  print(f"Error converting '{column}' to {astype}: {e}")
4354
4459
 
4355
4460
  # Return the modified DataFrame if inplace is False
4356
- if not inplace:
4357
- return df
4461
+ return df
4358
4462
 
4359
4463
 
4360
4464
  # ! DataFrame
py2ls/plot.py CHANGED
@@ -31,7 +31,7 @@ def df_corr(
31
31
  row_cluster=True, # Perform clustering on rows
32
32
  col_cluster=True, # Perform clustering on columns
33
33
  dendrogram_ratio=(0.2, 0.1), # Adjust size of dendrograms
34
- cbar_pos=(0.02, 0.8, 0.03, 0.2), # Adjust colorbar position
34
+ cbar_pos=(0.02, 1, 0.02, 0.1), # Adjust colorbar position
35
35
  xticklabels=True, # Show column labels
36
36
  yticklabels=True, # Show row labels
37
37
  **kwargs,
@@ -94,7 +94,7 @@ def df_corr(
94
94
  )
95
95
  else:
96
96
  # Create a standard heatmap
97
- plt.figure(figsize=(10, 8))
97
+ plt.figure(figsize=figsize)
98
98
  ax = sns.heatmap(
99
99
  correlation_matrix,
100
100
  mask=mask_array,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2ls
3
- Version: 0.1.10.27
3
+ Version: 0.2.1
4
4
  Summary: py(thon)2(too)ls
5
5
  Author: Jianfeng
6
6
  Author-email: Jianfeng.Liu0413@gmail.com
@@ -207,15 +207,15 @@ py2ls/doc.py,sha256=xN3g1OWfoaGUhikbJ0NqbN5eKy1VZVvWwRlhHMgyVEc,4243
207
207
  py2ls/export_requirements.py,sha256=x2WgUF0jYKz9GfA1MVKN-MdsM-oQ8yUeC6Ua8oCymio,2325
208
208
  py2ls/freqanalysis.py,sha256=F4218VSPbgL5tnngh6xNCYuNnfR-F_QjECUUxrPYZss,32594
209
209
  py2ls/ich2ls.py,sha256=3E9R8oVpyYZXH5PiIQgT3CN5NxLe4Dwtm2LwaeacE6I,21381
210
- py2ls/ips.py,sha256=TMmk9kwxY8KWFWLbNpTxD4nad95uMpXgSqke0S-gAMo,161096
210
+ py2ls/ips.py,sha256=HjMZDXzfOiqhgNOdtoX7dxoY2cRsrD78LXilWyIUffE,164940
211
211
  py2ls/netfinder.py,sha256=vgOOMhzwbjRuLWMAPyf_kh3HoOhsJ9dlA-tCkMf7kNU,55371
212
212
  py2ls/ocr.py,sha256=5lhUbJufIKRSOL6wAWVLEo8TqMYSjoI_Q-IO-_4u3DE,31419
213
- py2ls/plot.py,sha256=vkKwppGLjErM6s1L0JOhukX54XbfKXUl6ojhVztCBN4,100538
213
+ py2ls/plot.py,sha256=x_bvQyPM6sl7IscgHPUbOEnqR82Iefcyur1JOweEAZw,100536
214
214
  py2ls/setuptools-70.1.0-py3-none-any.whl,sha256=2bi3cUVal8ip86s0SOvgspteEF8SKLukECi-EWmFomc,882588
215
215
  py2ls/sleep_events_detectors.py,sha256=bQA3HJqv5qnYKJJEIhCyhlDtkXQfIzqksnD0YRXso68,52145
216
216
  py2ls/stats.py,sha256=fJmXQ9Lq460StOn-kfEljE97cySq7876HUPTnpB5hLs,38123
217
217
  py2ls/translator.py,sha256=zBeq4pYZeroqw3DT-5g7uHfVqKd-EQptT6LJ-Adi8JY,34244
218
218
  py2ls/wb_detector.py,sha256=7y6TmBUj9exCZeIgBAJ_9hwuhkDh1x_-yg4dvNY1_GQ,6284
219
- py2ls-0.1.10.27.dist-info/METADATA,sha256=vby3fz3bfQ7SzPfG49id_MWTInQE1VGqFRxRca7sahs,20040
220
- py2ls-0.1.10.27.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
221
- py2ls-0.1.10.27.dist-info/RECORD,,
219
+ py2ls-0.2.1.dist-info/METADATA,sha256=Qr6DFCoJWEj0_JrHmUDLJYRtoPqO7GyHth0Apsq5wOk,20036
220
+ py2ls-0.2.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
221
+ py2ls-0.2.1.dist-info/RECORD,,