Skip to content

Commit

Permalink
Remove pandas dependency from mat_set
Browse files Browse the repository at this point in the history
  • Loading branch information
softwaredoug committed Oct 28, 2024
1 parent bbff25c commit c49a386
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions searcharray/utils/mat_set.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import numpy as np
import pandas as pd
import numbers
import abc


def _is_list_like(obj):
if isinstance(obj, np.ndarray):
return len(obj.shape) > 0
elif isinstance(obj, list):
return True
return (
# equiv: `isinstance(obj, abc.Iterable)`
isinstance(obj, abc.Iterable)
# we do not count strings/unicode/bytes as list-like
# exclude Generic types that have __iter__
and not isinstance(obj, (str, bytes))
# exclude zero-dimensional duck-arrays, effectively scalars
and not (hasattr(obj, "ndim") and obj.ndim == 0)
)


class SparseMatSetBuilder:
Expand Down Expand Up @@ -110,7 +126,7 @@ def __setitem__(self, index, value):
raise ValueError("This sparse matrix only supports setting 1")
self.set_cols(row, np.asarray([col]))
# Multiple rows
elif pd.api.types.is_list_like(index):
elif _is_list_like(index):
if len(index) == len(value):
for idx, val in zip(index, value):
self[idx] = val
Expand Down

0 comments on commit c49a386

Please sign in to comment.