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

FIX-#5829: fix ndarray assignment via loc #5847

Merged
merged 3 commits into from
Apr 3, 2023

Conversation

anmyachev
Copy link
Collaborator

@anmyachev anmyachev commented Mar 23, 2023

What do these changes do?

  • first commit message and PR title follow format outlined here

    NOTE: If you edit the PR title to match this format, you need to add another commit (even if it's empty) or amend your last commit for the CI job that checks the PR title to pick up the new PR title.

  • passes flake8 modin/ asv_bench/benchmarks scripts/doc_checker.py
  • passes black --check modin/ asv_bench/benchmarks scripts/doc_checker.py
  • signed commit with git commit -s
  • Resolves BUG: Syntax Error in modin > pandas > indexing.py:829 #5829
  • tests added and passing
  • module layout described at docs/development/architecture.rst is up-to-date

@anmyachev anmyachev marked this pull request as ready for review March 23, 2023 18:36
@anmyachev anmyachev requested a review from a team as a code owner March 23, 2023 18:36
@@ -821,22 +821,23 @@ def _setitem_with_new_columns(self, row_loc, col_loc, item):
"Must have equal len keys and value when setting with an iterable"
)
else:
if item.shape != (len(self.qc.index, len(col_loc))):
if item.shape != (len(row_loc), len(col_loc)):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that we need to compare the lengths of the keys with the object that we insert.

if not all(common_label_loc):
# In this case we have some new cols and some old ones
columns = self.qc.columns
for i in range(len(common_label_loc)):
if not common_label_loc[i]:
columns = columns.insert(len(columns), col_loc[i])
self.qc = self.qc.reindex(labels=columns, axis=1, fill_value=0)
self.qc = self.qc.reindex(labels=columns, axis=1, fill_value=np.NaN)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently the behavior in pandas has been changed.

if len(item.shape) > 1
else item[common_label_loc]
)
if not isinstance(item, np.ndarray):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least in the case when the keys are strings, we will get an empty array here, which is not true.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate please? I still don't understand why the check for numpy array is needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous comment is not entirely correct.

This part of the code was responsible for not taking those columns from the assigned value that were not in the query compiler, however this behavior is not true for loc operation, since missed columns will be added in the next few lines via reindex op.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering also that in this code branch there can only be a numpy array, I completely deleted this code.

Signed-off-by: Anatoly Myachev <anatoly.myachev@intel.com>
Signed-off-by: Anatoly Myachev <anatoly.myachev@intel.com>
Signed-off-by: Anatoly Myachev <anatoly.myachev@intel.com>
@anmyachev
Copy link
Collaborator Author

@dchigarev anything else?

@dchigarev dchigarev merged commit 18d4738 into modin-project:master Apr 3, 2023
@anmyachev anmyachev deleted the issue5829 branch April 3, 2023 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Syntax Error in modin > pandas > indexing.py:829
2 participants