Skip to content

Commit

Permalink
Remove numpy import
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Aug 31, 2024
1 parent 15f89b8 commit 8aacfa7
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions param/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import logging
import numbers
import operator
import random
import re
import sys
import types
Expand Down Expand Up @@ -3815,6 +3814,9 @@ def pprint(val,imports=None, prefix="\n ", settings=[],
elif type(val) in script_repr_reg:
rep = script_repr_reg[type(val)](val,imports,prefix,settings)

elif type(val) in (_np_random(), _py_random()):
rep = None

elif isinstance(val, Parameterized) or (type(val) is type and issubclass(val, Parameterized)):
rep=val.param.pprint(imports=imports, prefix=prefix+" ",
qualify=qualify, unknown_value=unknown_value,
Expand Down Expand Up @@ -3849,17 +3851,16 @@ def container_script_repr(container,imports,prefix,settings):
return rep


def empty_script_repr(*args): # pyflakes:ignore (unused arguments):
return None
def _np_random():
if "numpy" in sys.modules:
import numpy as np
return np.random.RandomState

try:
# Suppress scriptrepr for objects not yet having a useful string representation
import numpy
script_repr_reg[random.Random] = empty_script_repr
script_repr_reg[numpy.random.RandomState] = empty_script_repr

except ImportError:
pass # Support added only if those libraries are available
def _py_random():
if "random" in sys.modules:
import random
return random.Random


def function_script_repr(fn,imports,prefix,settings):
Expand Down

0 comments on commit 8aacfa7

Please sign in to comment.