Skip to content

Commit

Permalink
Don't fail on non-numeric types, fix #14, release 0.2.12
Browse files Browse the repository at this point in the history
  • Loading branch information
xl0 committed May 14, 2024
1 parent 583a7ab commit 8e834eb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lovely_numpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.2.11"
__version__ = "0.2.12"

from .repr_str import *
from .repr_rgb import *
Expand Down
8 changes: 4 additions & 4 deletions lovely_numpy/repr_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ def plain_repr(x):
return repr(x)

# %% ../nbs/00_repr_str.ipynb 10
def lovely( x :Union[np.ndarray, np.generic], # The data you want to explore
def lovely( x :Union[np.ndarray, np.generic], # The data you want to explore
plain :bool =False, # Plain old way
verbose :bool =False, # Both summaty and plain
depth :int =0, # Show deeper summary, up to `depth`
lvl :int =0, # Indentation level
lvl :int =0, # Indentation level
color :O[bool]=None # Override `get_config().color`
) -> str: # The summary

"Pretty-print the stats of a numpy array or scalar"

if plain or not isinstance(x, (np.ndarray, np.generic)) or np.iscomplexobj(x):
if plain or not isinstance(x, (np.ndarray, np.generic)) or np.iscomplexobj(x) or not np.issubdtype(x.dtype, np.number):
return plain_repr(x)

conf = get_config()
Expand All @@ -72,7 +72,7 @@ def lovely( x :Union[np.ndarray, np.generic], # The data you want to explo

common = np_to_str_common(x, color=color)
dtype = short_dtype(x)

vals = pretty_str(x) if 0 < x.size <= 10 else None
res = sparse_join([type_str, dtype, numel, common, vals])

Expand Down
32 changes: 28 additions & 4 deletions nbs/00_repr_str.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,17 @@
"source": [
"# |export\n",
"\n",
"def lovely( x :Union[np.ndarray, np.generic], # The data you want to explore \n",
"def lovely( x :Union[np.ndarray, np.generic], # The data you want to explore\n",
" plain :bool =False, # Plain old way\n",
" verbose :bool =False, # Both summaty and plain\n",
" depth :int =0, # Show deeper summary, up to `depth`\n",
" lvl :int =0, # Indentation level \n",
" lvl :int =0, # Indentation level\n",
" color :O[bool]=None # Override `get_config().color`\n",
" ) -> str: # The summary\n",
"\n",
" \"Pretty-print the stats of a numpy array or scalar\"\n",
"\n",
" if plain or not isinstance(x, (np.ndarray, np.generic)) or np.iscomplexobj(x):\n",
" if plain or not isinstance(x, (np.ndarray, np.generic)) or np.iscomplexobj(x) or not np.issubdtype(x.dtype, np.number):\n",
" return plain_repr(x)\n",
"\n",
" conf = get_config()\n",
Expand All @@ -163,7 +163,7 @@
"\n",
" common = np_to_str_common(x, color=color)\n",
" dtype = short_dtype(x)\n",
" \n",
"\n",
" vals = pretty_str(x) if 0 < x.size <= 10 else None\n",
" res = sparse_join([type_str, dtype, numel, common, vals])\n",
"\n",
Expand Down Expand Up @@ -538,6 +538,30 @@
"print(lovely(c))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"array(['a', 'b', 'c'], dtype='<U1')\n",
"array([{}, {'a': 1}, {'b': 2, 'c': 3}], dtype=object)\n"
]
}
],
"source": [
"# Other weirs stuff\n",
"\n",
"w = np.array([\"a\", \"b\", \"c\"])\n",
"print(lovely(w))\n",
"\n",
"z = np.array([{}, {\"a\": 1}, {\"b\": 2, \"c\": 3}])\n",
"print(lovely(z))"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
2 changes: 1 addition & 1 deletion settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
### Python library ###
repo = lovely-numpy
lib_name = lovely-numpy
version = 0.2.11
version = 0.2.12
min_python = 3.7
license = MIT

Expand Down

0 comments on commit 8e834eb

Please sign in to comment.