Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix: facilitate scalar check for more generic objects like datetime, sets as well #42

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/tidypandas/tidyframe_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,7 @@ def _mutate(self, dictionary, order_by = None, **kwargs):
keys = dictionary.keys()
# ensure new column names to be created are valid (do not start with '_')
keys_flattened = list(
np.concatenate([[x] if np.isscalar(x) else list(x) for x in keys])
np.concatenate([[x] if (np.ndim(x) == 0) else list(x) for x in keys])
)
assert np.all([_is_valid_colname(x) for x in keys_flattened]),\
(f"column names to be created/modified should be valid column names. "
Expand All @@ -1790,7 +1790,7 @@ def _mutate(self, dictionary, order_by = None, **kwargs):
keys = dictionary.keys()
# ensure new column names to be created are valid (do not start with '_')
keys_flattened = list(
np.concatenate([[x] if np.isscalar(x) else list(x) for x in keys])
np.concatenate([[x] if (np.ndim(x) == 0) else list(x) for x in keys])
)
assert np.all([_is_valid_colname(x) for x in keys_flattened]),\
(f"column names to be created/modified should be valid column names. "
Expand Down Expand Up @@ -1826,7 +1826,7 @@ def _mutate(self, dictionary, order_by = None, **kwargs):

# 1. direct assign
if isinstance(rhs, ((pd.Series, np.ndarray))
or np.isscalar(rhs)):
or (np.ndim(rhs) == 0)):
mutated[akey] = rhs

# 2. assign via function -- pandas style UDF
Expand Down Expand Up @@ -2266,7 +2266,7 @@ def mutate(self
keys = dictionary.keys()
keys_flattened = list(
np.concatenate(
[[x] if np.isscalar(x) else list(x) for x in keys]
[[x] if (np.ndim(x) == 0) else list(x) for x in keys]
)
)
# keys should not intersect with 'by' columns
Expand Down Expand Up @@ -2323,8 +2323,8 @@ def _summarise(self, dictionary, **kwargs):

def _validate_rhs_val(akey, rhs_val):
if not pd.isna(rhs_val):
if not np.isscalar(rhs_val):
if not (len(rhs_val) == 1 and np.isscalar(rhs_val[0])):
if not (np.ndim(rhs_val) == 0):
if not (len(rhs_val) == 1 and (np.ndim(rhs_val[0]) == 0)):
raise Exception((f"Summarised value for key {akey} does not"
" turn out to be a scalar or cannot be "
"converted to a scalar")
Expand Down Expand Up @@ -2678,7 +2678,7 @@ def summarise(self
keys = dictionary.keys()
keys_flattened = list(
np.concatenate(
[[x] if np.isscalar(x) else list(x) for x in keys]
[[x] if (np.ndim(x) == 0) else list(x) for x in keys]
)
)
assert len(set(by).intersection(keys_flattened)) == 0,\
Expand Down Expand Up @@ -3831,7 +3831,7 @@ def pivot_wider(self
"'names_from' or 'values_from'"
)
if values_fill is not None:
assert np.isscalar(values_fill),\
assert np.ndim(values_fill) == 0,\
"arg 'values_fill' should be a scalar"

assert (values_fn is None
Expand Down Expand Up @@ -5546,7 +5546,7 @@ def unnest(self, nest_column_name = 'data'):
def is_list_scalar_na(x):
if isinstance(x, (list, pd.core.arrays.floating.FloatingArray)):
res = True
elif np.isscalar(x):
elif np.ndim(x) == 0:
res = True
elif isinstance(pd.isna(x), bool) and pd.isna(x):
res = True
Expand Down