Skip to content

Commit

Permalink
[numpy] use importExternal for all imports of numpy #1808
Browse files Browse the repository at this point in the history
  • Loading branch information
anjakefala committed Mar 31, 2023
1 parent 0ad3f17 commit 547488b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions visidata/loaders/npy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def open_npz(vd, p):

class NpySheet(Sheet):
def iterload(self):
import numpy
vd.importExternal('numpy')
if not hasattr(self, 'npy'):
self.npy = numpy.load(str(self.source), encoding='bytes', **self.options.getall('npy_'))
self.reloadCols()
Expand Down Expand Up @@ -47,12 +47,12 @@ class NpzSheet(vd.ZipSheet):
]

def iterload(self):
import numpy
vd.importExternal('numpy')
self.npz = numpy.load(str(self.source), encoding='bytes', **self.options.getall('npy_'))
yield from Progress(self.npz.items())

def openRow(self, row):
import numpy
vd.importExternal('numpy')
tablename, tbl = row
if isinstance(tbl, numpy.ndarray):
return NpySheet(tablename, npy=tbl)
Expand All @@ -62,7 +62,7 @@ def openRow(self, row):

@VisiData.api
def save_npy(vd, p, sheet):
import numpy as np
np = vd.importExternal('numpy')

dtype = []

Expand Down
4 changes: 2 additions & 2 deletions visidata/loaders/pandas_freqtbl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class DataFrameRowSliceAdapter:
by visidata's selectRow implementation.
"""
def __init__(self, df, mask):
import pandas as pd
import numpy as np
pd = vd.importExternal('pandas')
np = vd.importExternal('numpy')
if not isinstance(df, pd.DataFrame):
vd.fail('%s is not a dataframe' % type(df).__name__)
if not isinstance(mask, pd.Series):
Expand Down

0 comments on commit 547488b

Please sign in to comment.