Skip to content

Conversation

@antareepsarkar
Copy link

@antareepsarkar antareepsarkar commented Nov 10, 2025

Description

It checks the value of ndim when the argument for data is an np.ndarray in pandas.array(data, dtype=None, copy=True)

Reason

import pandas as pd
a = pd.array(np.array([[1], [2]]))

Raises an error because the array is 2-D

import pandas as pd
a = pd.array(np.array([[1], ['a']]))

Does not raise an error in this case(maybe, because the value is now a string). But, it should raise an error as only 1-D arrays can be passed as arguments.

resolves #63112

@antareepsarkar antareepsarkar marked this pull request as draft November 11, 2025 05:33
@antareepsarkar antareepsarkar marked this pull request as ready for review November 11, 2025 16:48
@antareepsarkar
Copy link
Author

antareepsarkar commented Nov 12, 2025

Please review this.

@Alvaro-Kothe
Copy link
Member

Does this PR address an open issue?

@antareepsarkar
Copy link
Author

antareepsarkar commented Nov 14, 2025

Does this PR address an open issue?

Not any issue which I know of. But, I thought that it should raise an error. So, I made the PR.

@Alvaro-Kothe
Copy link
Member

Sorry for being pedantic about this, but since this is a change in behavior, I think it's best to:

  1. create an issue;
  2. mark this PR to close that issue;
  3. update this PR with a whatsnew note and create tests.

@antareepsarkar
Copy link
Author

antareepsarkar commented Nov 14, 2025

Sorry for being pedantic about this, but since this is a change in behavior, I think it's best to:

  1. create an issue;
  2. mark this PR to close that issue;
  3. update this PR with a whatsnew note and create tests.

I will do what you said. But, I am still learning. I do not know to create tests. Please help me with that.

@antareepsarkar
Copy link
Author

Issue created for this PR #63112

@Alvaro-Kothe
Copy link
Member

I think that pandas/tests/arrays/test_array.py is an appropriate location for the test. Look at the current tests to have an idea on how to create them. It's easier to advise on a solution if there is something concrete.

@antareepsarkar
Copy link
Author

I think that pandas/tests/arrays/test_array.py is an appropriate location for the test. Look at the current tests to have an idea on how to create them. It's easier to advise on a solution if there is something concrete.

I will do that. Should I make a new PR for that?

@Alvaro-Kothe
Copy link
Member

I will do that. Should I make a new PR for that?

It should be done in this one.

@antareepsarkar
Copy link
Author

antareepsarkar commented Nov 15, 2025

I will do that. Should I make a new PR for that?

It should be done in this one.

Thank you for helping. I will create the tests.

@antareepsarkar
Copy link
Author

pre-commit failed because the max characters allowed in a line exceeded. I did not know about the max allowed characters. Sorry for that.
Are there any more changes that I should make?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: pandas.array works fine when 2-D array contains string

2 participants