Skip to content

Commit

Permalink
replace try with specific ifs
Browse files Browse the repository at this point in the history
  • Loading branch information
dcolinmorgan committed Jul 10, 2024
1 parent 6d7df64 commit 3462b97
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions graphistry/ai_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pandas as pd
import numpy as np

from inspect import getmodule
import graphistry

from .constants import DISTANCE, WEIGHT, BATCH
Expand Down Expand Up @@ -422,9 +422,9 @@ def infer_self_graph(res,
assert (
emb.shape[0] == df.shape[0]
), "minibatches emb and X must have same number of rows since h(df) = emb"
try:
if emb.x is not None:
df = df.assign(x=emb.x, y=emb.y) # add x and y to df for graphistry instance
except AttributeError:
else:
df = df.assign(x=emb[0], y=emb[1]) # if umap kwargs n_components > 2, take first 2 here
else: # if umap has been fit, but only transforming over features, need to add x and y or breaks plot binds of res
df['x'] = np.random.random(df.shape[0])
Expand Down Expand Up @@ -454,9 +454,9 @@ def infer_self_graph(res,
diff = np.array(diff, dtype = 'float')
except TypeError:
pass
try:
if 'pandas' in str(getmodule(diff)):
dist = np.linalg.norm(diff, axis=1) # Euclidean distance
except TypeError:
else:
dist = np.linalg.norm(diff.to_pandas(), axis=1) # Euclidean distance
mdists.append(dist)

Expand Down
2 changes: 1 addition & 1 deletion graphistry/dep_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _add_deps(self, pkg:str):
except:
pass

def import_from(self,pkg:str, name:str):
def import_from(self, pkg:str, name:str):
try:
module = __import__(pkg, fromlist=[name])
self.pkgs[name] = module
Expand Down

0 comments on commit 3462b97

Please sign in to comment.