Skip to content

Commit 1950cf7

Browse files
authored
lint(): run various linting tools to improve code style (#39)
1 parent bfc1989 commit 1950cf7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+215
-280
lines changed

pose_evaluation/analysis/analyze_scores.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
import argparse
2-
from typing import Optional, List, Dict, Tuple
3-
from collections import defaultdict
4-
from pathlib import Path
52
import json
6-
import re
7-
8-
import pandas as pd
93
import numpy as np
10-
from tqdm import tqdm
4+
import pandas as pd
5+
import re
116
import torch
7+
from collections import defaultdict
8+
from pathlib import Path
129
from torchmetrics.retrieval import RetrievalMAP, RetrievalMRR, RetrievalPrecision, RetrievalRecall
10+
from tqdm import tqdm
11+
from typing import Optional, List, Dict, Tuple
1312

14-
from pose_evaluation.evaluation.score_dataframe_format import ScoreDFCol, load_score_csv
1513
from pose_evaluation.evaluation.index_score_files import ScoresIndexDFCol, index_scores
1614
from pose_evaluation.evaluation.load_pyarrow_dataset import load_dataset, load_metric_dfs
15+
from pose_evaluation.evaluation.score_dataframe_format import ScoreDFCol, load_score_csv
1716

1817
_SIGNATURE_RE = re.compile(r"default_distance:([\d.]+)")
1918
_DEFAULTDIST_RE = re.compile(r"defaultdist([\d.]+)")
2019

21-
2220
tqdm.pandas()
2321

2422

@@ -514,6 +512,5 @@ def load_metric_dfs_from_filenames(scores_folder: Path, file_format: str = "csv"
514512
else:
515513
print("No metrics were analyzed.")
516514

517-
518515
# conda activate /opt/home/cleong/envs/pose_eval_src && cd /opt/home/cleong/projects/pose-evaluation && python pose_evaluation/evaluation/analyze_scores.py metric_results_1_2_z_combined_818_metrics/scores --file-format parquet
519516
# conda activate /opt/home/cleong/envs/pose_eval_src && cd /opt/home/cleong/projects/pose-evaluation && python pose_evaluation/evaluation/analyze_scores.py metric_results_round_4/scores/ --file-format parquet

pose_evaluation/analysis/correlate_and_graph_intergloss_scores.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
from itertools import combinations
2-
import math
3-
from pathlib import Path
4-
from typing import Optional
1+
import ast
2+
import gc
53
import hashlib
6-
from datetime import datetime
4+
import math
5+
import matplotlib.pyplot as plt
76
import pandas as pd
87
import plotly.express as px
98
import plotly.graph_objects as go
10-
from tqdm import tqdm
119
import seaborn as sns
12-
import gc
13-
import ast
10+
from datetime import datetime
11+
from itertools import combinations
12+
from pathlib import Path
1413
from scipy.stats import pearsonr, spearmanr, kendalltau, ttest_rel
15-
import matplotlib.pyplot as plt
16-
14+
from tqdm import tqdm
15+
from typing import Optional
1716

1817
sns.set_theme()
1918

pose_evaluation/analysis/count_files_by_hour.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python3
22

33
import argparse
4-
from pathlib import Path
54
from collections import Counter
65
from datetime import datetime, timedelta
6+
from pathlib import Path
77
from tqdm import tqdm
88

99

pose_evaluation/analysis/explore_metric_stats.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
from pathlib import Path
2-
from itertools import combinations
3-
import re
1+
import io
42
import os
5-
import torch
6-
import streamlit as st
73
import pandas as pd
84
import plotly.express as px
95
import plotly.graph_objects as go
106
import plotly.io as pio
11-
import io
7+
import re
8+
import streamlit as st
9+
import torch
10+
from itertools import combinations
11+
from pathlib import Path
1212
from typing import List, Tuple
1313

1414
# pio.templates.default = "plotly"
@@ -260,7 +260,6 @@ def prettify_axis_label(label: str) -> str:
260260

261261

262262
def apply_minimal_layout(fig: go.Figure, size: int = 600) -> None:
263-
264263
# fig.update_layout(
265264
# title=None,
266265
# xaxis=dict(visible=False),
@@ -753,7 +752,7 @@ def match_keywords(text):
753752
# f"\n% {interpret_name(metric)}",
754753
f"\n% {descriptive_name(metric)}",
755754
f"\n% {metric} &\t{metric_row['mean_average_precision']:.2f} &\t{metric_row['precision@10']:.2f}\t\\\\",
756-
f"\n{descriptive_name(metric).split()[0]} & {dd} & {fm} & {trim} & {norm} & {seq_align} & {kp} &\t{metric_row['mean_average_precision']*100:.0f}\\% &\t{metric_row['precision@10']*100:.0f}\\%\t\\\\",
755+
f"\n{descriptive_name(metric).split()[0]} & {dd} & {fm} & {trim} & {norm} & {seq_align} & {kp} &\t{metric_row['mean_average_precision'] * 100:.0f}\\% &\t{metric_row['precision@10'] * 100:.0f}\\%\t\\\\",
757756
]
758757

759758
for mdl in markdown_lines:
@@ -876,11 +875,10 @@ def match_keywords(text):
876875
st.write(f"**Average on '{sort_col}' without '{kw}':** `{avg_without:.4f}`")
877876
st.write(f"**Estimated effect on '{sort_col}' of '{kw}':** `{delta:+.4f}`")
878877
st.write(f"{kw} count within {top_or_bottom} 100 by {sort_col}: {(has_kw['RANK'] <= 100).sum()}")
879-
st.write(f"{kw} count within {top_or_bottom} 10 by {sort_col}: {(has_kw['RANK']<= 10).sum()}")
878+
st.write(f"{kw} count within {top_or_bottom} 10 by {sort_col}: {(has_kw['RANK'] <= 10).sum()}")
880879
st.write(f"{kw} count within {top_or_bottom} 5 by {sort_col}: {(has_kw['RANK'] <= 5).sum()}")
881880

882881
if st.checkbox(f"Show distributions for {kw}?"):
883-
884882
fig = go.Figure()
885883

886884
fig.add_trace(
@@ -1026,5 +1024,4 @@ def match_keywords(text):
10261024
else:
10271025
plot_pareto_frontier(df)
10281026

1029-
10301027
# conda activate /opt/home/cleong/envs/pose_eval_src && streamlit run pose_evaluation/evaluation/explore_metric_stats.py

pose_evaluation/analysis/plot_dtw.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from itertools import product
2-
from pathlib import Path
3-
41
import numpy as np
52
import plotly.graph_objects as go
63
import plotly.io as pio
74
from fastdtw import fastdtw # type: ignore (pylint can't find it but it's there)
5+
from itertools import product
6+
from pathlib import Path
87

98

109
def pad_seq(seq, val, count):

pose_evaluation/evaluation/add_semantic_and_lookalike_to_gloss_dfs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""WIP script to try and add relations to dataset_dfs, depends on fixing gloss/vocabulary matching problems"""
22

3-
from pathlib import Path
43
import pandas as pd
4+
from pathlib import Path
55

6-
from pose_evaluation.evaluation.load_splits_and_run_metrics import combine_dataset_dfs
76
from pose_evaluation.evaluation.combine_semantic_and_lookalike import create_gloss_tuple
7+
from pose_evaluation.evaluation.load_splits_and_run_metrics import combine_dataset_dfs
88

99
# /opt/home/cleong/projects/pose-evaluation/pose_evaluation/evaluation/combine_semantic_and_lookalike.py
1010

pose_evaluation/evaluation/analyze_scores_dask.py

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
from pathlib import Path
21
import argparse
3-
4-
2+
import argparse
3+
import dask.array as da
4+
import dask.bag as db
5+
import dask.dataframe as dd
6+
import dask.dataframe as dd
57
import numpy as np
68
import pandas as pd
7-
89
import pyarrow.dataset as ds
10+
from dask.distributed import LocalCluster
11+
from pathlib import Path
912

10-
import dask.dataframe as dd
11-
import dask.array as da
12-
import dask.bag as db
13-
13+
# client.close()
14+
# cluster.close()
15+
from pathlib import Path
1416

1517
# # https://docs.dask.org/en/latest/dataframe-hive.html#reading-parquet-data-with-hive-partitioning
1618
# # https://docs.dask.org/en/stable/deploying.html?utm_source=tds&utm_medium=pyarrow-in-pandas-and-dask
17-
1819
# if __name__ == "__main__":
1920
# from dask.distributed import LocalCluster
20-
2121
# cluster = LocalCluster() # Fully-featured local Dask cluster
2222
# client = cluster.get_client()
2323
# parser = argparse.ArgumentParser(description="Analyze")
2424
# parser.add_argument("dataset_dir", type=Path, help="Pyarrow Dataset of scores")
2525
# args = parser.parse_args()
26-
2726
# # Assuming your data is already in a Dask DataFrame 'ddf'
2827
# # as indicated by dd.read_parquet
2928
# try:
@@ -34,17 +33,12 @@
3433
# except Exception as e:
3534
# print(f"Error reading parquet files: {e}")
3635
# exit(1)
37-
3836
# # Filter the Dask DataFrame where "GLOSS_A" is equal to "GLOSS_B"
3937
# # filtered_ddf = ddf[ddf["GLOSS_A"] == ddf["GLOSS_B"]]
40-
4138
# # # Group by "METRIC" and calculate the mean of "SCORE" on the filtered data
4239
# # mean_scores = filtered_ddf.groupby("METRIC", observed=True)["SCORE"].mean()
43-
4440
# mean_scores = ddf.groupby("METRIC", observed=True)["SCORE"].mean()
45-
4641
# print(cluster.dashboard_link)
47-
4842
# # Compute the result to get a Pandas Series
4943
# try:
5044
# result = mean_scores.compute()
@@ -55,13 +49,6 @@
5549
# print(f"Error during computation: {e}")
5650
# finally:
5751

58-
# client.close()
59-
# cluster.close()
60-
from pathlib import Path
61-
import argparse
62-
import dask.dataframe as dd
63-
from dask.distributed import LocalCluster
64-
6552
if __name__ == "__main__":
6653
cluster = LocalCluster()
6754
client = cluster.get_client()

pose_evaluation/evaluation/analyze_scores_polars.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
import polars as pl
2-
from pathlib import Path
31
import argparse
2+
import os
3+
import polars as pl
44
import polars as pl
5-
from pathlib import Path
6-
75
import polars as pl
8-
9-
10-
import time
116
import psutil
12-
import os
137
import statistics
8+
import time
9+
from pathlib import Path
10+
from pathlib import Path
1411

1512

1613
def run_experiments(path: Path, limit_rows: int = 100_000_000, runs: int = 10):
@@ -129,7 +126,6 @@ def show_head(lf: pl.LazyFrame, n=5):
129126

130127

131128
def compute_score_by_metric(lf: pl.LazyFrame):
132-
133129
print(lf.schema)
134130

135131
lazy_result = lf.group_by("METRIC").agg(pl.col("SCORE").mean().alias("mean_SCORE"))
@@ -270,7 +266,7 @@ def compute_map_by_metric_safe_chunked(
270266
for i in range(0, len(gloss_a_paths), batch_size):
271267
batch_paths = gloss_a_paths[i : i + batch_size]
272268
print(
273-
f" 📁 Processing batch {i//batch_size + 1}/{(len(gloss_a_paths) + batch_size - 1)//batch_size} ({len(batch_paths)} paths)"
269+
f" 📁 Processing batch {i // batch_size + 1}/{(len(gloss_a_paths) + batch_size - 1) // batch_size} ({len(batch_paths)} paths)"
274270
)
275271

276272
batch_lf = metric_lf.filter(pl.col("GLOSS_A_PATH").is_in(batch_paths))
@@ -557,7 +553,7 @@ def compute_map_single_metric_chunked(lf: pl.LazyFrame, metric_name: str, chunk_
557553
for i in range(0, len(unique_paths), chunk_size):
558554
chunk_paths = unique_paths[i : i + chunk_size]
559555
print(
560-
f" 📦 Processing chunk {i//chunk_size + 1}/{(len(unique_paths) + chunk_size - 1)//chunk_size} "
556+
f" 📦 Processing chunk {i // chunk_size + 1}/{(len(unique_paths) + chunk_size - 1) // chunk_size} "
561557
f"({len(chunk_paths)} paths)"
562558
)
563559

@@ -645,7 +641,7 @@ def compute_map_ultra_minimal_memory(dataset_path: str, metrics_to_process: list
645641
# Process each query (GLOSS_A_PATH) individually
646642
for i, path in enumerate(unique_paths):
647643
if i % 1000 == 0:
648-
print(f" 📍 Processing query {i+1}/{len(unique_paths)}")
644+
print(f" 📍 Processing query {i + 1}/{len(unique_paths)}")
649645

650646
# Get data for this specific query
651647
query_lf = (

pose_evaluation/evaluation/combine_semantic_and_lookalike.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from pathlib import Path
21
import pandas as pd
32
from io import StringIO
3+
from pathlib import Path
44

55
"""Trying to combine Sem-Lex, ASL Citizen, ASL Knowledge Graph and "Known Lookalikes" from
66
"""

pose_evaluation/evaluation/compare_two_poses.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from typing import List
2-
import typer
31
import pandas as pd
4-
from pose_format import Pose
2+
import typer
53
from pathlib import Path
4+
from pose_format import Pose
5+
from typing import List
6+
67
from pose_evaluation.evaluation.create_metrics import get_metrics
78
from pose_evaluation.evaluation.load_splits_and_run_metrics import get_filtered_metrics
89

@@ -63,7 +64,6 @@ def compare(
6364
None, help="Will filter metrics to only those that include none of these"
6465
),
6566
):
66-
6767
# paths_csvs = Path("/opt/home/cleong/projects/pose-evaluation/debug_zspeed/zspeed_results_from_preliminary/").glob(
6868
# "*.csv"
6969
# )

0 commit comments

Comments
 (0)