Skip to content

Backport PR #31203 on branch 1.0.x (numpydev ragged array dtype warning) #31209

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

Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,7 @@ def drop(self, codes, level=None, errors="raise"):

if not isinstance(codes, (np.ndarray, Index)):
try:
codes = com.index_labels_to_array(codes)
codes = com.index_labels_to_array(codes, dtype=object)
except ValueError:
pass

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def cat_core(list_of_columns: List, sep: str):
return np.sum(arr_of_cols, axis=0)
list_with_sep = [sep] * (2 * len(list_of_columns) - 1)
list_with_sep[::2] = list_of_columns
arr_with_sep = np.asarray(list_with_sep)
arr_with_sep = np.asarray(list_with_sep, dtype=object)
return np.sum(arr_with_sep, axis=0)


Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/categorical/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,6 @@ def test_constructor_imaginary(self):
@pytest.mark.skipif(_np_version_under1p16, reason="Skipping for NumPy <1.16")
def test_constructor_string_and_tuples(self):
# GH 21416
c = pd.Categorical(["c", ("a", "b"), ("b", "a"), "c"])
c = pd.Categorical(np.array(["c", ("a", "b"), ("b", "a"), "c"], dtype=object))
expected_index = pd.Index([("a", "b"), ("b", "a"), "c"])
assert c.categories.equals(expected_index)
2 changes: 1 addition & 1 deletion pandas/tests/arrays/categorical/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_fillna_iterable_category(self, named):
Point = collections.namedtuple("Point", "x y")
else:
Point = lambda *args: args # tuple
cat = Categorical([Point(0, 0), Point(0, 1), None])
cat = Categorical(np.array([Point(0, 0), Point(0, 1), None], dtype=object))
result = cat.fillna(Point(0, 0))
expected = Categorical([Point(0, 0), Point(0, 1), Point(0, 0)])

Expand Down
10 changes: 7 additions & 3 deletions pandas/tests/extension/base/getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ def test_take_non_na_fill_value(self, data_missing):
fill_value = data_missing[1] # valid
na = data_missing[0]

array = data_missing._from_sequence([na, fill_value, na])
array = data_missing._from_sequence(
[na, fill_value, na], dtype=data_missing.dtype
)
result = array.take([-1, 1], fill_value=fill_value, allow_fill=True)
expected = array.take([1, 1])
self.assert_extension_array_equal(result, expected)
Expand Down Expand Up @@ -293,10 +295,12 @@ def test_reindex_non_na_fill_value(self, data_missing):
valid = data_missing[1]
na = data_missing[0]

array = data_missing._from_sequence([na, valid])
array = data_missing._from_sequence([na, valid], dtype=data_missing.dtype)
ser = pd.Series(array)
result = ser.reindex([0, 1, 2], fill_value=valid)
expected = pd.Series(data_missing._from_sequence([na, valid, valid]))
expected = pd.Series(
data_missing._from_sequence([na, valid, valid], dtype=data_missing.dtype)
)

self.assert_series_equal(result, expected)

Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/extension/json/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ def __setitem__(self, key, value):
def __len__(self) -> int:
return len(self.data)

def __array__(self, dtype=None):
if dtype is None:
dtype = object
return np.asarray(self.data, dtype=dtype)

@property
def nbytes(self) -> int:
return sys.getsizeof(self.data)
Expand Down
4 changes: 0 additions & 4 deletions pandas/tests/extension/json/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ def test_unstack(self, data, index):
# this matches otherwise
return super().test_unstack(data, index)

@pytest.mark.xfail(reason="Inconsistent sizes.")
def test_transpose(self, data):
super().test_transpose(data)


class TestGetitem(BaseJSON, base.BaseGetitemTests):
pass
Expand Down