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

.loc[ lambda, 'col'] = x got error TypeError: 'function' object is not iterable #3234

Closed
eromoe opened this issue Jul 13, 2021 · 0 comments · Fixed by #3518
Closed

.loc[ lambda, 'col'] = x got error TypeError: 'function' object is not iterable #3234

eromoe opened this issue Jul 13, 2021 · 0 comments · Fixed by #3518
Labels
bug 🦗 Something isn't working

Comments

@eromoe
Copy link

eromoe commented Jul 13, 2021

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): windows 10
  • Modin version (modin.__version__): 0.10.0
  • Python version: 3.8.8
  • Code we can use to reproduce:

Test code:

df = pd.DataFrame([[1, 2], [4, 5], [7, 8]],
     index=[7, 8, 9], columns=['max_speed', 'shield'])
df.loc[lambda df: df['shield'] == 8, 'max_speed'] = 0

this is valid in pandas.

got error :

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-101-f9afffa1da7a> in <module>
----> 1 df.loc[lambda df: df['shield'] == 8, 'max_speed'] = 0

~\anaconda3\lib\site-packages\modin\pandas\indexing.py in __setitem__(self, key, item)
    594             self.qc = self.df._query_compiler
    595         else:
--> 596             row_lookup, col_lookup = self._compute_lookup(row_loc, col_loc)
    597             super(_LocIndexer, self).__setitem__(
    598                 row_lookup,

~\anaconda3\lib\site-packages\modin\pandas\indexing.py in _compute_lookup(self, row_loc, col_loc)
    675             row_lookup = [i for i, row_val in enumerate(row_loc) if row_val]
    676         else:
--> 677             row_lookup = self.qc.index.get_indexer_for(row_loc)
    678         if isinstance(col_loc, slice):
    679             col_lookup = self.qc.columns.get_indexer_for(

~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_indexer_for(self, target, **kwargs)
   4958         """
   4959         if self._index_as_unique:
-> 4960             return self.get_indexer(target, **kwargs)
   4961         indexer, _ = self.get_indexer_non_unique(target)
   4962         return indexer

~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_indexer(self, target, method, limit, tolerance)
   3145     ) -> np.ndarray:
   3146         method = missing.clean_reindex_fill_method(method)
-> 3147         target = ensure_index(target)
   3148         if tolerance is not None:
   3149             tolerance = self._convert_tolerance(tolerance, target)

~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in ensure_index(index_like, copy)
   5915             index_like = copy_func(index_like)
   5916 
-> 5917     return Index(index_like)
   5918 
   5919 

~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in __new__(cls, data, dtype, copy, name, tupleize_cols, **kwargs)
    388                     )
    389             # other iterable of some kind
--> 390             subarr = com.asarray_tuplesafe(data, dtype=object)
    391             return Index(subarr, dtype=dtype, copy=copy, name=name, **kwargs)
    392 

~\anaconda3\lib\site-packages\pandas\core\common.py in asarray_tuplesafe(values, dtype)
    199 
    200     if not (isinstance(values, (list, tuple)) or hasattr(values, "__array__")):
--> 201         values = list(values)
    202     elif isinstance(values, ABCIndexClass):
    203         return values._values

TypeError: 'function' object is not iterable

@eromoe eromoe added the bug 🦗 Something isn't working label Jul 13, 2021
mvashishtha pushed a commit to mvashishtha/modin that referenced this issue Oct 6, 2021
…aFrame.iloc.

- For getting values with loc(), allow using a callable to specify rows while using a non-callable to specify columns.
- Allow setting values with callabes in loc().
- Allow setting values with callables in iloc().

The new test cases fail without this change.

Signed-off-by: mvashishtha <mahesh@ponder.io>
devin-petersohn pushed a commit that referenced this issue Oct 6, 2021
…3518)

- For getting values with loc(), allow using a callable to specify rows while using a non-callable to specify columns.
- Allow setting values with callabes in loc().
- Allow setting values with callables in iloc().

The new test cases fail without this change.

Signed-off-by: mvashishtha <mahesh@ponder.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🦗 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant