py2ls 0.2.2__py3-none-any.whl → 0.2.3__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/.DS_Store +0 -0
- py2ls/data/usages_pd.json +56 -0
- py2ls/ips.py +49 -12
- py2ls/plot.py +20 -82
- py2ls/update2usage.py +126 -0
- {py2ls-0.2.2.dist-info → py2ls-0.2.3.dist-info}/METADATA +1 -1
- {py2ls-0.2.2.dist-info → py2ls-0.2.3.dist-info}/RECORD +8 -6
- {py2ls-0.2.2.dist-info → py2ls-0.2.3.dist-info}/WHEEL +0 -0
py2ls/.DS_Store
CHANGED
Binary file
|
@@ -0,0 +1,56 @@
|
|
1
|
+
{
|
2
|
+
"pd.read_pickle": "pd.read_pickle(filepath_or_buffer,compression='infer',storage_options=None)",
|
3
|
+
"df.to_pickle": "df.to_pickle(path,*,compression='infer',protocol=5,storage_options=None)",
|
4
|
+
"pd.read_table": "pd.read_table(filepath_or_buffer,*,sep=<no_default>,delimiter=None,header='infer',names=<no_default>,index_col=None,usecols=None,dtype=None,engine=None,converters=None,true_values=None,false_values=None,skipinitialspace=False,skiprows=None,skipfooter=0,nrows=None,na_values=None,keep_default_na=True,na_filter=True,verbose=<no_default>,skip_blank_lines=True,parse_dates=False,infer_datetime_format=<no_default>,keep_date_col=<no_default>,date_parser=<no_default>,date_format=None,dayfirst=False,cache_dates=True,iterator=False,chunksize=None,compression='infer',thousands=None,decimal='.',lineterminator=None,quotechar='\"',quoting=0,doublequote=True,escapechar=None,comment=None,encoding=None,encoding_errors='strict',dialect=None,on_bad_lines='error',delim_whitespace=<no_default>,low_memory=True,memory_map=False,float_precision=None,storage_options=None,dtype_backend=<no_default>)",
|
5
|
+
"pd.read_csv": "pd.read_csv(filepath_or_buffer,*,sep=<no_default>,delimiter=None,header='infer',names=<no_default>,index_col=None,usecols=None,dtype=None,engine=None,converters=None,true_values=None,false_values=None,skipinitialspace=False,skiprows=None,skipfooter=0,nrows=None,na_values=None,keep_default_na=True,na_filter=True,verbose=<no_default>,skip_blank_lines=True,parse_dates=None,infer_datetime_format=<no_default>,keep_date_col=<no_default>,date_parser=<no_default>,date_format=None,dayfirst=False,cache_dates=True,iterator=False,chunksize=None,compression='infer',thousands=None,decimal='.',lineterminator=None,quotechar='\"',quoting=0,doublequote=True,escapechar=None,comment=None,encoding=None,encoding_errors='strict',dialect=None,on_bad_lines='error',delim_whitespace=<no_default>,low_memory=True,memory_map=False,float_precision=None,storage_options=None,dtype_backend=<no_default>)",
|
6
|
+
"df.to_csv": "df.to_csv(path_or_buf=None,*,sep=',',na_rep='',float_format=None,columns=None,header=True,index=True,index_label=None,mode='w',encoding=None,compression='infer',quoting=None,quotechar='\"',lineterminator=None,chunksize=None,date_format=None,doublequote=True,escapechar=None,decimal='.',errors='strict',storage_options=None)",
|
7
|
+
"pd.read_fwf": "pd.read_fwf(filepath_or_buffer,*,colspecs='infer',widths=None,infer_nrows=100,dtype_backend=<no_default>,iterator=False,chunksize=None,**kwds)",
|
8
|
+
"pd.read_clipboard": "pd.read_clipboard(sep='\\\\s+',dtype_backend=<no_default>,**kwargs)",
|
9
|
+
"pd.read_excel": "pd.read_excel(io,sheet_name=0,*,header=0,names=None,index_col=None,usecols=None,dtype=None,engine=None,converters=None,true_values=None,false_values=None,skiprows=None,nrows=None,na_values=None,keep_default_na=True,na_filter=True,verbose=False,parse_dates=False,date_parser=<no_default>,date_format=None,thousands=None,decimal='.',comment=None,skipfooter=0,storage_options=None,dtype_backend=<no_default>,engine_kwargs=None)",
|
10
|
+
"df.to_excel": "df.to_excel(excel_writer,*,sheet_name='Sheet1',na_rep='',float_format=None,columns=None,header=True,index=True,index_label=None,startrow=0,startcol=0,engine=None,merge_cells=True,inf_rep='inf',freeze_panes=None,storage_options=None,engine_kwargs=None)",
|
11
|
+
"classpandas.ExcelFile": "classpandas.ExcelFile(path_or_buffer,engine=None,storage_options=None,engine_kwargs=None)",
|
12
|
+
"propertyExcelFile.book": "propertyExcelFile.book",
|
13
|
+
"propertyExcelFile.sheet_names": "propertyExcelFile.sheet_names",
|
14
|
+
"ExcelFile.parse": "ExcelFile.parse(sheet_name=0,header=0,names=None,index_col=None,usecols=None,converters=None,true_values=None,false_values=None,skiprows=None,nrows=None,na_values=None,parse_dates=False,date_parser=<no_default>,date_format=None,thousands=None,comment=None,skipfooter=0,dtype_backend=<no_default>,**kwds)",
|
15
|
+
"Styler.to_excel": "Styler.to_excel(excel_writer,sheet_name='Sheet1',na_rep='',float_format=None,columns=None,header=True,index=True,index_label=None,startrow=0,startcol=0,engine=None,merge_cells=True,encoding=None,inf_rep='inf',verbose=True,freeze_panes=None,storage_options=None)",
|
16
|
+
"classpandas.ExcelWriter": "classpandas.ExcelWriter(path,engine=None,date_format=None,datetime_format=None,mode='w',storage_options=None,if_sheet_exists=None,engine_kwargs=None)",
|
17
|
+
"pd.read_json": "pd.read_json(path_or_buf,*,orient=None,typ='frame',dtype=None,convert_axes=None,convert_dates=True,keep_default_dates=True,precise_float=False,date_unit=None,encoding=None,encoding_errors='strict',lines=False,chunksize=None,compression='infer',nrows=None,storage_options=None,dtype_backend=<no_default>,engine='ujson')",
|
18
|
+
"pd.json_normalize": "pd.json_normalize(data,record_path=None,meta=None,meta_prefix=None,record_prefix=None,errors='raise',sep='.',max_level=None)",
|
19
|
+
"df.to_json": "df.to_json(path_or_buf=None,*,orient=None,date_format=None,double_precision=10,force_ascii=True,date_unit='ms',default_handler=None,lines=False,compression='infer',index=None,indent=None,storage_options=None,mode='w')",
|
20
|
+
"pd.io.json.build_table_schema": "pd.io.json.build_table_schema(data,index=True,primary_key=None,version=True)",
|
21
|
+
"pd.read_html": "pd.read_html(io,*,match='.+',flavor=None,header=None,index_col=None,skiprows=None,attrs=None,parse_dates=False,thousands=',',encoding=None,decimal='.',converters=None,na_values=None,keep_default_na=True,displayed_only=True,extract_links=None,dtype_backend=<no_default>,storage_options=None)",
|
22
|
+
"df.to_html": "df.to_html(buf=None,*,columns=None,col_space=None,header=True,index=True,na_rep='NaN',formatters=None,float_format=None,sparsify=None,index_names=True,justify=None,max_rows=None,max_cols=None,show_dimensions=False,decimal='.',bold_rows=True,classes=None,escape=True,notebook=False,border=None,table_id=None,render_links=False,encoding=None)",
|
23
|
+
"Styler.to_html": "Styler.to_html(buf=None,*,table_uuid=None,table_attributes=None,sparse_index=None,sparse_columns=None,bold_headers=False,caption=None,max_rows=None,max_columns=None,encoding=None,doctype_html=False,exclude_styles=False,**kwargs)",
|
24
|
+
"pd.read_xml": "pd.read_xml(path_or_buffer,*,xpath='./*',namespaces=None,elems_only=False,attrs_only=False,names=None,dtype=None,converters=None,parse_dates=None,encoding='utf-8',parser='lxml',stylesheet=None,iterparse=None,compression='infer',storage_options=None,dtype_backend=<no_default>)",
|
25
|
+
"df.to_xml": "df.to_xml(path_or_buffer=None,*,index=True,root_name='data',row_name='row',na_rep=None,attr_cols=None,elem_cols=None,namespaces=None,prefix=None,encoding='utf-8',xml_declaration=True,pretty_print=True,parser='lxml',stylesheet=None,compression='infer',storage_options=None)",
|
26
|
+
"df.to_latex": "df.to_latex(buf=None,*,columns=None,header=True,index=True,na_rep='NaN',formatters=None,float_format=None,sparsify=None,index_names=True,bold_rows=False,column_format=None,longtable=None,escape=None,encoding=None,decimal='.',multicolumn=None,multicolumn_format=None,multirow=None,caption=None,label=None,position=None)",
|
27
|
+
"Styler.to_latex": "Styler.to_latex(buf=None,*,column_format=None,position=None,position_float=None,hrules=None,clines=None,label=None,caption=None,sparse_index=None,sparse_columns=None,multirow_align=None,multicol_align=None,siunitx=False,environment=None,encoding=None,convert_css=False)",
|
28
|
+
"pd.read_hdf": "pd.read_hdf(path_or_buf,key=None,mode='r',errors='strict',where=None,start=None,stop=None,columns=None,iterator=False,chunksize=None,**kwargs)",
|
29
|
+
"HDFStore.put": "HDFStore.put(key,value,format=None,index=True,append=False,complib=None,complevel=None,min_itemsize=None,nan_rep=None,data_columns=None,encoding=None,errors='strict',track_times=True,dropna=False)",
|
30
|
+
"HDFStore.append": "HDFStore.append(key,value,format=None,axes=None,index=True,append=True,complib=None,complevel=None,columns=None,min_itemsize=None,nan_rep=None,chunksize=None,expectedrows=None,dropna=None,data_columns=None,encoding=None,errors='strict')",
|
31
|
+
"HDFStore.get": "HDFStore.get(key)",
|
32
|
+
"HDFStore.select": "HDFStore.select(key,where=None,start=None,stop=None,columns=None,iterator=False,chunksize=None,auto_close=False)",
|
33
|
+
"HDFStore.info": "HDFStore.info()",
|
34
|
+
"HDFStore.keys": "HDFStore.keys(include='pandas')",
|
35
|
+
"HDFStore.groups": "HDFStore.groups()",
|
36
|
+
"HDFStore.walk": "HDFStore.walk(where='/')",
|
37
|
+
"pd.read_feather": "pd.read_feather(path,columns=None,use_threads=True,storage_options=None,dtype_backend=<no_default>)",
|
38
|
+
"df.to_feather": "df.to_feather(path,**kwargs)",
|
39
|
+
"pd.read_parquet": "pd.read_parquet(path,engine='auto',columns=None,storage_options=None,use_nullable_dtypes=<no_default>,dtype_backend=<no_default>,filesystem=None,filters=None,**kwargs)",
|
40
|
+
"df.to_parquet": "df.to_parquet(path=None,*,engine='auto',compression='snappy',index=None,partition_cols=None,storage_options=None,**kwargs)",
|
41
|
+
"pd.read_orc": "pd.read_orc(path,columns=None,dtype_backend=<no_default>,filesystem=None,**kwargs)",
|
42
|
+
"df.to_orc": "df.to_orc(path=None,*,engine='pyarrow',index=None,engine_kwargs=None)",
|
43
|
+
"pd.read_sas": "pd.read_sas(filepath_or_buffer,*,format=None,index=None,encoding=None,chunksize=None,iterator=False,compression='infer')",
|
44
|
+
"pd.read_spss": "pd.read_spss(path,usecols=None,convert_categoricals=True,dtype_backend=<no_default>)",
|
45
|
+
"pd.read_sql_table": "pd.read_sql_table(table_name,con,schema=None,index_col=None,coerce_float=True,parse_dates=None,columns=None,chunksize=None,dtype_backend=<no_default>)",
|
46
|
+
"pd.read_sql_query": "pd.read_sql_query(sql,con,index_col=None,coerce_float=True,params=None,parse_dates=None,chunksize=None,dtype=None,dtype_backend=<no_default>)",
|
47
|
+
"pd.read_sql": "pd.read_sql(sql,con,index_col=None,coerce_float=True,params=None,parse_dates=None,columns=None,chunksize=None,dtype_backend=<no_default>,dtype=None)",
|
48
|
+
"df.to_sql": "df.to_sql(name,con,*,schema=None,if_exists='fail',index=True,index_label=None,chunksize=None,dtype=None,method=None)",
|
49
|
+
"pd.read_gbq": "pd.read_gbq(query,project_id=None,index_col=None,col_order=None,reauth=False,auth_local_webserver=True,dialect=None,location=None,configuration=None,credentials=None,use_bqstorage_api=None,max_results=None,progress_bar_type=None)",
|
50
|
+
"pd.read_stata": "pd.read_stata(filepath_or_buffer,*,convert_dates=True,convert_categoricals=True,index_col=None,convert_missing=False,preserve_dtypes=True,columns=None,order_categoricals=True,chunksize=None,iterator=False,compression='infer',storage_options=None)",
|
51
|
+
"df.to_stata": "df.to_stata(path,*,convert_dates=None,write_index=True,byteorder=None,time_stamp=None,data_label=None,variable_labels=None,version=114,convert_strl=None,compression='infer',storage_options=None,value_labels=None)",
|
52
|
+
"propertyStataReader.data_label": "propertyStataReader.data_label",
|
53
|
+
"StataReader.value_labels": "StataReader.value_labels()",
|
54
|
+
"StataReader.variable_labels": "StataReader.variable_labels()",
|
55
|
+
"StataWriter.write_file": "StataWriter.write_file()"
|
56
|
+
}
|
py2ls/ips.py
CHANGED
@@ -1551,10 +1551,14 @@ def fload(fpath, kind=None, **kwargs):
|
|
1551
1551
|
content = file.read()
|
1552
1552
|
return content
|
1553
1553
|
|
1554
|
-
def load_json(fpath):
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1554
|
+
def load_json(fpath, **kwargs):
|
1555
|
+
output=kwargs.pop("output","json")
|
1556
|
+
if output=='json':
|
1557
|
+
with open(fpath, "r") as file:
|
1558
|
+
content = json.load(file)
|
1559
|
+
return content
|
1560
|
+
else:
|
1561
|
+
return pd.read_json(fpath,**kwargs)
|
1558
1562
|
|
1559
1563
|
def load_yaml(fpath):
|
1560
1564
|
with open(fpath, "r") as file:
|
@@ -1616,6 +1620,11 @@ def fload(fpath, kind=None, **kwargs):
|
|
1616
1620
|
comment = kwargs.get("comment", None)
|
1617
1621
|
kwargs.pop("comment", None)
|
1618
1622
|
|
1623
|
+
fmt=kwargs.pop("fmt",False)
|
1624
|
+
if verbose:
|
1625
|
+
print_pd_usage("read_csv", verbose=verbose)
|
1626
|
+
return
|
1627
|
+
|
1619
1628
|
if comment is None:
|
1620
1629
|
comment = get_comment(
|
1621
1630
|
fpath, comment=None, encoding="utf-8", lines_to_check=5
|
@@ -1743,7 +1752,9 @@ def fload(fpath, kind=None, **kwargs):
|
|
1743
1752
|
|
1744
1753
|
def load_xlsx(fpath, **kwargs):
|
1745
1754
|
engine = kwargs.get("engine", "openpyxl")
|
1746
|
-
kwargs.pop("
|
1755
|
+
verbose=kwargs.pop("verbose",False)
|
1756
|
+
if verbose:
|
1757
|
+
print_pd_usage("read_excel", verbose=verbose)
|
1747
1758
|
df = pd.read_excel(fpath, engine=engine, **kwargs)
|
1748
1759
|
return df
|
1749
1760
|
|
@@ -1813,7 +1824,6 @@ def fload(fpath, kind=None, **kwargs):
|
|
1813
1824
|
if kind is None:
|
1814
1825
|
_, kind = os.path.splitext(fpath)
|
1815
1826
|
kind = kind.lower()
|
1816
|
-
|
1817
1827
|
kind = kind.lstrip(".").lower()
|
1818
1828
|
img_types = [
|
1819
1829
|
"bmp",
|
@@ -4291,8 +4301,6 @@ def preview(var):
|
|
4291
4301
|
# preview(pd.DataFrame({"Name": ["Alice", "Bob"], "Age": [25, 30]}))
|
4292
4302
|
# preview({"key": "value", "numbers": [1, 2, 3]})
|
4293
4303
|
|
4294
|
-
|
4295
|
-
# ! DataFrame
|
4296
4304
|
def df_as_type(
|
4297
4305
|
df: pd.DataFrame,
|
4298
4306
|
columns: Optional[Union[str, List[str]]] = None,
|
@@ -4301,6 +4309,18 @@ def df_as_type(
|
|
4301
4309
|
inplace: bool = True,
|
4302
4310
|
errors: str = "coerce", # Can be "ignore", "raise", or "coerce"
|
4303
4311
|
**kwargs,
|
4312
|
+
):
|
4313
|
+
return df_astype(df=df,columns=columns,astype=astype,format=format,inplace=inplace,errors=errors,**kwargs)
|
4314
|
+
|
4315
|
+
# ! DataFrame
|
4316
|
+
def df_astype(
|
4317
|
+
df: pd.DataFrame,
|
4318
|
+
columns: Optional[Union[str, List[str]]] = None,
|
4319
|
+
astype: str = "datetime",
|
4320
|
+
fmt: Optional[str] = None,
|
4321
|
+
inplace: bool = True,
|
4322
|
+
errors: str = "coerce", # Can be "ignore", "raise", or "coerce"
|
4323
|
+
**kwargs,
|
4304
4324
|
) -> Optional[pd.DataFrame]:
|
4305
4325
|
"""
|
4306
4326
|
Convert specified columns of a DataFrame to a specified type (e.g., datetime, float, int, numeric, timedelta).
|
@@ -4310,7 +4330,7 @@ def df_as_type(
|
|
4310
4330
|
- df: DataFrame containing the columns to convert.
|
4311
4331
|
- columns: Either a single column name, a list of column names, or None to convert all columns.
|
4312
4332
|
- astype: The target type to convert the columns to ('datetime', 'float', 'int', 'numeric', 'timedelta', etc.).
|
4313
|
-
-
|
4333
|
+
- fmt: Optional; format to specify the datetime format (only relevant for 'datetime' conversion).
|
4314
4334
|
- inplace: Whether to modify the DataFrame in place or return a new one. Defaults to False.
|
4315
4335
|
- errors: Can be "ignore", "raise", or "coerce"
|
4316
4336
|
- **kwargs: Additional keyword arguments to pass to the conversion function (e.g., errors='ignore' for pd.to_datetime or pd.to_numeric).
|
@@ -4390,7 +4410,7 @@ def df_as_type(
|
|
4390
4410
|
# convert it as type: datetime
|
4391
4411
|
if isinstance(column, int):
|
4392
4412
|
df.iloc[:, column] = pd.to_datetime(
|
4393
|
-
df.iloc[:, column], format=
|
4413
|
+
df.iloc[:, column], format=fmt, errors=errors, **kwargs
|
4394
4414
|
)
|
4395
4415
|
# further convert:
|
4396
4416
|
if astype == "time":
|
@@ -4412,9 +4432,9 @@ def df_as_type(
|
|
4412
4432
|
else:
|
4413
4433
|
df[column] = (
|
4414
4434
|
pd.to_datetime(
|
4415
|
-
df[column], format=
|
4435
|
+
df[column], format=fmt, errors=errors, **kwargs
|
4416
4436
|
)
|
4417
|
-
if
|
4437
|
+
if fmt
|
4418
4438
|
else pd.to_datetime(df[column], errors=errors, **kwargs)
|
4419
4439
|
)
|
4420
4440
|
# further convert:
|
@@ -5227,3 +5247,20 @@ def evaluate_cluster(
|
|
5227
5247
|
metrics["V-Measure"] = np.nan
|
5228
5248
|
|
5229
5249
|
return metrics
|
5250
|
+
|
5251
|
+
|
5252
|
+
def print_pd_usage(
|
5253
|
+
func_name="excel",
|
5254
|
+
verbose=True,
|
5255
|
+
dir_json="/Users/macjianfeng/Dropbox/github/python/py2ls/py2ls/data/usages_pd.json",
|
5256
|
+
):
|
5257
|
+
default_settings = fload(dir_json, output='json')
|
5258
|
+
valid_kinds = list(default_settings.keys())
|
5259
|
+
kind = strcmp(func_name, valid_kinds)[0]
|
5260
|
+
usage=default_settings[kind]
|
5261
|
+
if verbose:
|
5262
|
+
for i, i_ in enumerate(ssplit(usage, by=",")):
|
5263
|
+
i_ = i_.replace("=", "\t= ") + ","
|
5264
|
+
print(i_) if i == 0 else print("\t", i_)
|
5265
|
+
else:
|
5266
|
+
print(usage)
|
py2ls/plot.py
CHANGED
@@ -20,71 +20,6 @@ from .netfinder import get_soup, fetch
|
|
20
20
|
logging.getLogger("fontTools").setLevel(logging.WARNING)
|
21
21
|
|
22
22
|
|
23
|
-
def update_sns_usages(
|
24
|
-
url="https://seaborn.pydata.org/generated/seaborn.swarmplot.html",
|
25
|
-
dir_save=None,
|
26
|
-
):
|
27
|
-
"""
|
28
|
-
Fetches usage examples of various Seaborn plotting functions from the Seaborn documentation website.
|
29
|
-
It filters the relevant plot-related links, extracts usage examples, and saves them in a JSON file.
|
30
|
-
|
31
|
-
Parameters:
|
32
|
-
- url (str): URL of the Seaborn page to start extracting plot usages (default is swarmplot page).
|
33
|
-
- dir_save (str): Directory where the JSON file containing usages will be saved (default is a local path).
|
34
|
-
|
35
|
-
Saves:
|
36
|
-
- A JSON file named 'usages_sns.json' containing plotting function names and their usage descriptions.
|
37
|
-
|
38
|
-
Returns:
|
39
|
-
- None
|
40
|
-
"""
|
41
|
-
|
42
|
-
# extract each usage from its url
|
43
|
-
def get_usage(url):
|
44
|
-
sp = get_soup(url, driver="se")
|
45
|
-
# preview(sp)
|
46
|
-
return fetch(sp, where="dt")[0]
|
47
|
-
|
48
|
-
if dir_save is None:
|
49
|
-
if "mac" in get_os():
|
50
|
-
dir_save = "/Users/macjianfeng/Dropbox/github/python/py2ls/py2ls/data/"
|
51
|
-
else:
|
52
|
-
dir_save = "Z:\\Jianfeng\\temp\\"
|
53
|
-
sp = get_soup(url, driver="se")
|
54
|
-
links_all = fetch(sp, where="a", get="href", class_="reference internal")
|
55
|
-
filtered_links = unique(
|
56
|
-
[
|
57
|
-
i
|
58
|
-
for i in links_all
|
59
|
-
if not any(
|
60
|
-
[
|
61
|
-
i.startswith(cond)
|
62
|
-
for cond in [
|
63
|
-
"seaborn.JointGrid",
|
64
|
-
"seaborn.PairGrid",
|
65
|
-
"seaborn.objects",
|
66
|
-
]
|
67
|
-
]
|
68
|
-
+ ["plot" not in i]
|
69
|
-
)
|
70
|
-
]
|
71
|
-
)
|
72
|
-
links = ["https://seaborn.pydata.org/generated/" + i for i in filtered_links]
|
73
|
-
|
74
|
-
usages = [get_usage(i) for i in links]
|
75
|
-
dict_usage = {}
|
76
|
-
for usage in usages:
|
77
|
-
dict_usage.update(
|
78
|
-
{ssplit(usage, by="(")[0].replace("seaborn.", ""): usage[:-1]}
|
79
|
-
)
|
80
|
-
# save to local
|
81
|
-
dir_save += "/" if not dir_save.endswith("/") else ""
|
82
|
-
fsave(
|
83
|
-
dir_save + "usages_sns.json",
|
84
|
-
dict_usage,
|
85
|
-
)
|
86
|
-
|
87
|
-
|
88
23
|
def heatmap(
|
89
24
|
data,
|
90
25
|
ax=None,
|
@@ -2920,17 +2855,17 @@ def plot_xy(
|
|
2920
2855
|
# (1) return FcetGrid
|
2921
2856
|
if k == "jointplot":
|
2922
2857
|
kws_joint = kwargs.pop("kws_joint", kwargs)
|
2923
|
-
g = sns.jointplot(data=data, x=x, y=y,
|
2858
|
+
g = sns.jointplot(data=data, x=x, y=y, **kws_joint)
|
2924
2859
|
elif k == "lmplot":
|
2925
2860
|
kws_lm = kwargs.pop("kws_lm", kwargs)
|
2926
|
-
g = sns.lmplot(data=data, x=x, y=y,
|
2861
|
+
g = sns.lmplot(data=data, x=x, y=y, **kws_lm)
|
2927
2862
|
elif k == "catplot_sns":
|
2928
2863
|
kws_cat = kwargs.pop("kws_cat", kwargs)
|
2929
|
-
g = sns.catplot(data=data, x=x, y=y,
|
2864
|
+
g = sns.catplot(data=data, x=x, y=y, **kws_cat)
|
2930
2865
|
elif k == "displot":
|
2931
2866
|
kws_dis = kwargs.pop("kws_dis", kwargs)
|
2932
2867
|
# displot creates a new figure and returns a FacetGrid
|
2933
|
-
g = sns.displot(data=data, x=x,
|
2868
|
+
g = sns.displot(data=data, x=x, **kws_dis)
|
2934
2869
|
|
2935
2870
|
# (2) return axis
|
2936
2871
|
if ax is None:
|
@@ -2939,6 +2874,9 @@ def plot_xy(
|
|
2939
2874
|
if k == "catplot":
|
2940
2875
|
kws_cat = kwargs.pop("kws_cat", kwargs)
|
2941
2876
|
g = catplot(data=data, x=x, y=y, ax=ax, **kws_cat)
|
2877
|
+
elif k == "stdshade":
|
2878
|
+
kws_stdshade = kwargs.pop("kws_stdshade", kwargs)
|
2879
|
+
ax = stdshade(ax=ax, **kwargs)
|
2942
2880
|
elif k == "scatterplot":
|
2943
2881
|
kws_scatter = kwargs.pop("kws_scatter", kwargs)
|
2944
2882
|
palette = kws_scatter.pop(
|
@@ -2964,41 +2902,41 @@ def plot_xy(
|
|
2964
2902
|
)
|
2965
2903
|
elif k == "histplot":
|
2966
2904
|
kws_hist = kwargs.pop("kws_hist", kwargs)
|
2967
|
-
ax = sns.histplot(data=data, x=x,
|
2905
|
+
ax = sns.histplot(data=data, x=x, ax=ax, **kws_hist)
|
2968
2906
|
elif k == "kdeplot":
|
2969
2907
|
kws_kde = kwargs.pop("kws_kde", kwargs)
|
2970
|
-
ax = sns.kdeplot(data=data, x=x,
|
2908
|
+
ax = sns.kdeplot(data=data, x=x, ax=ax, **kws_kde)
|
2971
2909
|
elif k == "ecdfplot":
|
2972
2910
|
kws_ecdf = kwargs.pop("kws_ecdf", kwargs)
|
2973
|
-
ax = sns.ecdfplot(data=data, x=x,
|
2911
|
+
ax = sns.ecdfplot(data=data, x=x, ax=ax, **kws_ecdf)
|
2974
2912
|
elif k == "rugplot":
|
2975
2913
|
kws_rug = kwargs.pop("kws_rug", kwargs)
|
2976
2914
|
print(kws_rug)
|
2977
|
-
ax = sns.rugplot(data=data, x=x,
|
2915
|
+
ax = sns.rugplot(data=data, x=x, ax=ax, **kws_rug)
|
2978
2916
|
elif k == "stripplot":
|
2979
2917
|
kws_strip = kwargs.pop("kws_strip", kwargs)
|
2980
|
-
ax = sns.stripplot(data=data, x=x, y=y,
|
2918
|
+
ax = sns.stripplot(data=data, x=x, y=y, ax=ax, **kws_strip)
|
2981
2919
|
elif k == "swarmplot":
|
2982
2920
|
kws_swarm = kwargs.pop("kws_swarm", kwargs)
|
2983
|
-
ax = sns.swarmplot(data=data, x=x, y=y,
|
2921
|
+
ax = sns.swarmplot(data=data, x=x, y=y, ax=ax, **kws_swarm)
|
2984
2922
|
elif k == "boxplot":
|
2985
2923
|
kws_box = kwargs.pop("kws_box", kwargs)
|
2986
|
-
ax = sns.boxplot(data=data, x=x, y=y,
|
2924
|
+
ax = sns.boxplot(data=data, x=x, y=y, ax=ax, **kws_box)
|
2987
2925
|
elif k == "violinplot":
|
2988
2926
|
kws_violin = kwargs.pop("kws_violin", kwargs)
|
2989
|
-
ax = sns.violinplot(data=data, x=x, y=y,
|
2927
|
+
ax = sns.violinplot(data=data, x=x, y=y, ax=ax, **kws_violin)
|
2990
2928
|
elif k == "boxenplot":
|
2991
2929
|
kws_boxen = kwargs.pop("kws_boxen", kwargs)
|
2992
|
-
ax = sns.boxenplot(data=data, x=x, y=y,
|
2930
|
+
ax = sns.boxenplot(data=data, x=x, y=y, ax=ax, **kws_boxen)
|
2993
2931
|
elif k == "pointplot":
|
2994
2932
|
kws_point = kwargs.pop("kws_point", kwargs)
|
2995
|
-
ax = sns.pointplot(data=data, x=x, y=y,
|
2933
|
+
ax = sns.pointplot(data=data, x=x, y=y, ax=ax, **kws_point)
|
2996
2934
|
elif k == "barplot":
|
2997
2935
|
kws_bar = kwargs.pop("kws_bar", kwargs)
|
2998
|
-
ax = sns.barplot(data=data, x=x, y=y,
|
2936
|
+
ax = sns.barplot(data=data, x=x, y=y, ax=ax, **kws_bar)
|
2999
2937
|
elif k == "countplot":
|
3000
2938
|
kws_count = kwargs.pop("kws_count", kwargs)
|
3001
|
-
ax = sns.countplot(data=data, x=x,
|
2939
|
+
ax = sns.countplot(data=data, x=x, ax=ax, **kws_count)
|
3002
2940
|
elif k == "regplot":
|
3003
2941
|
kws_reg = kwargs.pop("kws_reg", kwargs)
|
3004
2942
|
ax = sns.regplot(data=data, x=x, y=y, ax=ax, **kws_reg)
|
@@ -3007,7 +2945,7 @@ def plot_xy(
|
|
3007
2945
|
ax = sns.residplot(data=data, x=x, y=y, lowess=True, ax=ax, **kws_resid)
|
3008
2946
|
elif k == "lineplot":
|
3009
2947
|
kws_line = kwargs.pop("kws_line", kwargs)
|
3010
|
-
ax = sns.lineplot(ax=ax, data=data, x=x, y=y,
|
2948
|
+
ax = sns.lineplot(ax=ax, data=data, x=x, y=y, **kws_line)
|
3011
2949
|
|
3012
2950
|
figsets(**kws_figsets)
|
3013
2951
|
print(k, " ⤵ ")
|
py2ls/update2usage.py
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
from .ips import *
|
2
|
+
from .netfinder import fetch, get_soup
|
3
|
+
|
4
|
+
|
5
|
+
def update_pd_usages(
|
6
|
+
url="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_clipboard.html",
|
7
|
+
dir_save=None,
|
8
|
+
):
|
9
|
+
# extract each usage from its url
|
10
|
+
def get_usage(url):
|
11
|
+
# extract each usage from its url
|
12
|
+
sp = get_soup(url, driver="se")
|
13
|
+
return fetch(sp, where="dt")[0]
|
14
|
+
|
15
|
+
if dir_save is None:
|
16
|
+
if "mac" in get_os():
|
17
|
+
dir_save = "/Users/macjianfeng/Dropbox/github/python/py2ls/py2ls/data/"
|
18
|
+
else:
|
19
|
+
dir_save = "Z:\\Jianfeng\\temp\\"
|
20
|
+
sp = get_soup(url, driver="se")
|
21
|
+
links_all = fetch(sp, where="a", get="href", class_="reference internal")
|
22
|
+
filtered_links = unique(
|
23
|
+
[i for i in links_all if any([i.startswith(cond) for cond in ["pandas"]])]
|
24
|
+
)
|
25
|
+
links = [
|
26
|
+
"https://pandas.pydata.org/docs/reference/api/" + i for i in filtered_links
|
27
|
+
]
|
28
|
+
|
29
|
+
usages = [get_usage(i) for i in links]
|
30
|
+
dict_usage = {}
|
31
|
+
for usage in usages:
|
32
|
+
if usage.startswith("DataFrame"):
|
33
|
+
usage = usage.replace("DataFrame", "df")
|
34
|
+
if usage.startswith("pandas"):
|
35
|
+
usage = usage.replace("pandas", "pd")
|
36
|
+
if usage.endswith("[source]#"):
|
37
|
+
usage = usage.replace("[source]#", "")
|
38
|
+
if usage.endswith("#"):
|
39
|
+
usage = usage.replace("#", "")
|
40
|
+
str2rm = ["class", "property"]
|
41
|
+
for str2rm_ in str2rm:
|
42
|
+
if usage.startswith(str2rm_):
|
43
|
+
usage = usage.replace(str2rm, "")
|
44
|
+
funcname = ssplit(usage, by="(")[0]
|
45
|
+
dict_usage.update({funcname: usage})
|
46
|
+
# save to local
|
47
|
+
dir_save += "/" if not dir_save.endswith("/") else ""
|
48
|
+
fsave(
|
49
|
+
dir_save + "usages_pd.json",
|
50
|
+
dict_usage,
|
51
|
+
)
|
52
|
+
|
53
|
+
|
54
|
+
def update_sns_usages(
|
55
|
+
url="https://seaborn.pydata.org/generated/seaborn.swarmplot.html",
|
56
|
+
dir_save=None,
|
57
|
+
):
|
58
|
+
"""
|
59
|
+
Fetches usage examples of various Seaborn plotting functions from the Seaborn documentation website.
|
60
|
+
It filters the relevant plot-related links, extracts usage examples, and saves them in a JSON file.
|
61
|
+
|
62
|
+
Parameters:
|
63
|
+
- url (str): URL of the Seaborn page to start extracting plot usages (default is swarmplot page).
|
64
|
+
- dir_save (str): Directory where the JSON file containing usages will be saved (default is a local path).
|
65
|
+
|
66
|
+
Saves:
|
67
|
+
- A JSON file named 'usages_sns.json' containing plotting function names and their usage descriptions.
|
68
|
+
|
69
|
+
Returns:
|
70
|
+
- None
|
71
|
+
"""
|
72
|
+
|
73
|
+
# extract each usage from its url
|
74
|
+
def get_usage(url):
|
75
|
+
sp = get_soup(url, driver="se")
|
76
|
+
# preview(sp)
|
77
|
+
return fetch(sp, where="dt")[0]
|
78
|
+
|
79
|
+
if dir_save is None:
|
80
|
+
if "mac" in get_os():
|
81
|
+
dir_save = "/Users/macjianfeng/Dropbox/github/python/py2ls/py2ls/data/"
|
82
|
+
else:
|
83
|
+
dir_save = "Z:\\Jianfeng\\temp\\"
|
84
|
+
sp = get_soup(url, driver="se")
|
85
|
+
links_all = fetch(sp, where="a", get="href", class_="reference internal")
|
86
|
+
filtered_links = unique(
|
87
|
+
[
|
88
|
+
i
|
89
|
+
for i in links_all
|
90
|
+
if not any(
|
91
|
+
[
|
92
|
+
i.startswith(cond)
|
93
|
+
for cond in [
|
94
|
+
"seaborn.JointGrid",
|
95
|
+
"seaborn.PairGrid",
|
96
|
+
"seaborn.objects",
|
97
|
+
]
|
98
|
+
]
|
99
|
+
+ ["plot" not in i]
|
100
|
+
)
|
101
|
+
]
|
102
|
+
)
|
103
|
+
links = ["https://seaborn.pydata.org/generated/" + i for i in filtered_links]
|
104
|
+
|
105
|
+
usages = [get_usage(i) for i in links]
|
106
|
+
dict_usage = {}
|
107
|
+
for usage in usages:
|
108
|
+
dict_usage.update(
|
109
|
+
{ssplit(usage, by="(")[0].replace("seaborn.", ""): usage[:-1]}
|
110
|
+
)
|
111
|
+
# save to local
|
112
|
+
dir_save += "/" if not dir_save.endswith("/") else ""
|
113
|
+
fsave(
|
114
|
+
dir_save + "usages_sns.json",
|
115
|
+
dict_usage,
|
116
|
+
)
|
117
|
+
|
118
|
+
|
119
|
+
def main():
|
120
|
+
# update pandas usage to local
|
121
|
+
update_pd_usages()
|
122
|
+
# update_sns_usages()
|
123
|
+
|
124
|
+
|
125
|
+
if __name__ == "__main__":
|
126
|
+
main()
|
@@ -1,4 +1,4 @@
|
|
1
|
-
py2ls/.DS_Store,sha256=
|
1
|
+
py2ls/.DS_Store,sha256=N6pp6R6M5ZPDw6IdIAnsHaAAOu8hWJASHMjjjKMNmOc,6148
|
2
2
|
py2ls/.git/COMMIT_EDITMSG,sha256=AdtqRHle5Ej2EBNPJY79v-SB454v5UK4wuPCPFELiFQ,11
|
3
3
|
py2ls/.git/FETCH_HEAD,sha256=VM-2Jiw6iPaGu0ftg9xwq76OyNPWV0iT1nL0VWiL1zI,100
|
4
4
|
py2ls/.git/HEAD,sha256=KNJb-Cr0wOK3L1CVmyvrhZ4-YLljCl6MYD2tTdsrboA,21
|
@@ -203,21 +203,23 @@ py2ls/data/styles/style6.json,sha256=tu-MYOT9x5Rorc-2IK6sy-J-frmz0RNdm65XAsDQKX4
|
|
203
203
|
py2ls/data/styles/style7.json,sha256=StdUFwIVrS7T_6CDrADHMorzc0WZFWBM7IyYdO1TPHg,4447
|
204
204
|
py2ls/data/styles/style8.json,sha256=8XUgkZtew8ebvjbAHlDHCSWUqNra3ktDvMCO4vNh-CM,4456
|
205
205
|
py2ls/data/styles/style9.json,sha256=PLxvntbH_kfzZlnCTtCEAUVBGi5m6Lngb9C01rArQog,4769
|
206
|
+
py2ls/data/usages_pd.json,sha256=XvFAwxKn6yYZztxmAhcqQ-kuYm6xBnLRx5aOLfvp3BQ,11060
|
206
207
|
py2ls/data/usages_sns.json,sha256=Vu2kGIIMxxWxJ1kW0Ov7mq47DQwZa_-gwsXiW72A2ag,7788
|
207
208
|
py2ls/db2ls.py,sha256=MMfFX47aIPIyu7fU9aPvX9lbPRPYOpJ_VXwlnWk-8qo,13615
|
208
209
|
py2ls/doc.py,sha256=xN3g1OWfoaGUhikbJ0NqbN5eKy1VZVvWwRlhHMgyVEc,4243
|
209
210
|
py2ls/export_requirements.py,sha256=x2WgUF0jYKz9GfA1MVKN-MdsM-oQ8yUeC6Ua8oCymio,2325
|
210
211
|
py2ls/freqanalysis.py,sha256=F4218VSPbgL5tnngh6xNCYuNnfR-F_QjECUUxrPYZss,32594
|
211
212
|
py2ls/ich2ls.py,sha256=3E9R8oVpyYZXH5PiIQgT3CN5NxLe4Dwtm2LwaeacE6I,21381
|
212
|
-
py2ls/ips.py,sha256=
|
213
|
+
py2ls/ips.py,sha256=uEpvsKo_E9eX49Icd60g-fQBDzmpGW65hJM9_mr6wuM,195254
|
213
214
|
py2ls/netfinder.py,sha256=vgOOMhzwbjRuLWMAPyf_kh3HoOhsJ9dlA-tCkMf7kNU,55371
|
214
215
|
py2ls/ocr.py,sha256=5lhUbJufIKRSOL6wAWVLEo8TqMYSjoI_Q-IO-_4u3DE,31419
|
215
|
-
py2ls/plot.py,sha256=
|
216
|
+
py2ls/plot.py,sha256=ynL5fz2jf1pD09FWkAayQOT3c4Jj64sjFHrkgCqdgAs,127193
|
216
217
|
py2ls/setuptools-70.1.0-py3-none-any.whl,sha256=2bi3cUVal8ip86s0SOvgspteEF8SKLukECi-EWmFomc,882588
|
217
218
|
py2ls/sleep_events_detectors.py,sha256=bQA3HJqv5qnYKJJEIhCyhlDtkXQfIzqksnD0YRXso68,52145
|
218
219
|
py2ls/stats.py,sha256=DMoJd8Z5YV9T1wB-4P52F5K5scfVK55DT8UP4Twcebo,38627
|
219
220
|
py2ls/translator.py,sha256=zBeq4pYZeroqw3DT-5g7uHfVqKd-EQptT6LJ-Adi8JY,34244
|
221
|
+
py2ls/update2usage.py,sha256=9uLoipgM0k-xUy56XOa6v-sOim3mE5srdNiPzn03ALY,3964
|
220
222
|
py2ls/wb_detector.py,sha256=7y6TmBUj9exCZeIgBAJ_9hwuhkDh1x_-yg4dvNY1_GQ,6284
|
221
|
-
py2ls-0.2.
|
222
|
-
py2ls-0.2.
|
223
|
-
py2ls-0.2.
|
223
|
+
py2ls-0.2.3.dist-info/METADATA,sha256=QvoGrLUwlS0T7VI09f-OJ8tU1Z3VGCl0bJWbP73RCCg,20036
|
224
|
+
py2ls-0.2.3.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
225
|
+
py2ls-0.2.3.dist-info/RECORD,,
|
File without changes
|