Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit29e0146

Browse files
Manju080mroeschkepre-commit-ci[bot]rhshadrach
authored
BUG: Impossible creation of array with dtype=string (#61263)
* DOC: Update warning in Index.values docstring to clarify index modification issues (#60954)* DOC: Update warning in Index.values docstring to clarify index modification issues (#60954) with changes* Update pandas/core/indexes/base.pyCo-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>* DOC : Fixing the whitespace which was causing error* Fixed docstring validation and formatting issues* BUG: Fix array creation for string dtype with inconsistent list lengths (#61155)* BUG: Fix array creation for string dtype with inconsistent list lengths (#61155)* BUG fix GH#61155 v2* BUG fix GH#61155 with test case for list of lists handling* Fix formatting in test_string_array.py (pre-commit autofix)* [pre-commit.ci] auto fixes from pre-commit.com hooksfor more information, seehttps://pre-commit.ci* Add test for list of lists handling in ensure_string_array (GH#61155)* fixing checks* [pre-commit.ci] auto fixes from pre-commit.com hooksfor more information, seehttps://pre-commit.ci* Update pandas/tests/libs/test_lib.pyCo-authored-by: Richard Shadrach <45562402+rhshadrach@users.noreply.github.com>* Remove pandas/tests/arrays/test_string_array.py as requested* wrong fiel base.py* Remove check for nested lists in scalars in string_.py first try* Revert unintended changes to base.py---------Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>Co-authored-by: Richard Shadrach <45562402+rhshadrach@users.noreply.github.com>
1 parente637b42 commit29e0146

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

‎pandas/_libs/lib.pyx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,10 @@ cpdef ndarray[object] ensure_string_array(
777777
return out
778778
arr= arr.to_numpy(dtype=object)
779779
elifnot util.is_array(arr):
780-
arr= np.array(arr,dtype="object")
780+
# GH#61155: Guarantee a 1-d result when array is a list of lists
781+
input_arr= arr
782+
arr= np.empty(len(arr),dtype="object")
783+
arr[:]= input_arr
781784

782785
result= np.asarray(arr,dtype="object")
783786

‎pandas/tests/libs/test_lib.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,13 @@ def test_ensure_string_array_copy():
297297
assertnotnp.shares_memory(arr,result)
298298
assertarr[1]isNone
299299
assertresult[1]isnp.nan
300+
301+
302+
deftest_ensure_string_array_list_of_lists():
303+
# GH#61155: ensure list of lists doesn't get converted to string
304+
arr= [list("test"),list("word")]
305+
result=lib.ensure_string_array(arr)
306+
307+
# Each item in result should still be a list, not a stringified version
308+
expected=np.array(["['t', 'e', 's', 't']","['w', 'o', 'r', 'd']"],dtype=object)
309+
tm.assert_numpy_array_equal(result,expected)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp