Skip to content

Commit 81e263b

Browse files
committed
wip
1 parent 59221a6 commit 81e263b

File tree

3 files changed

+11
-172
lines changed

3 files changed

+11
-172
lines changed

pandas/tests/indexing/test_at.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
from datetime import (
2-
datetime,
3-
timezone,
4-
)
5-
61
import numpy as np
72
import pytest
83

@@ -21,17 +16,6 @@
2116
import pandas._testing as tm
2217

2318

24-
def test_at_timezone():
25-
# https://github.com/pandas-dev/pandas/issues/33544
26-
result = DataFrame({"foo": [datetime(2000, 1, 1)]})
27-
with tm.assert_produces_warning(FutureWarning, match="incompatible dtype"):
28-
result.at[0, "foo"] = datetime(2000, 1, 2, tzinfo=timezone.utc)
29-
expected = DataFrame(
30-
{"foo": [datetime(2000, 1, 2, tzinfo=timezone.utc)]}, dtype=object
31-
)
32-
tm.assert_frame_equal(result, expected)
33-
34-
3519
def test_selection_methods_of_assigned_col():
3620
# GH 29282
3721
df = DataFrame(data={"a": [1, 2, 3], "b": [4, 5, 6]})

pandas/tests/indexing/test_iloc.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from pandas.errors import IndexingError
1010

1111
from pandas import (
12-
NA,
1312
Categorical,
1413
CategoricalDtype,
1514
DataFrame,
@@ -527,12 +526,6 @@ def test_iloc_setitem_frame_duplicate_columns_multiple_blocks(self):
527526
df.iloc[:, 0] = df.iloc[:, 0].astype("f8")
528527
assert len(df._mgr.blocks) == 1
529528

530-
# if the assigned values cannot be held by existing integer arrays,
531-
# we cast
532-
with tm.assert_produces_warning(FutureWarning, match="incompatible dtype"):
533-
df.iloc[:, 0] = df.iloc[:, 0] + 0.5
534-
assert len(df._mgr.blocks) == 2
535-
536529
expected = df.copy()
537530

538531
# assign back to self
@@ -1441,11 +1434,3 @@ def test_iloc_setitem_pure_position_based(self):
14411434
ser1.iloc[1:3] = ser2.iloc[1:3]
14421435
expected = Series([1, 5, 6])
14431436
tm.assert_series_equal(ser1, expected)
1444-
1445-
def test_iloc_nullable_int64_size_1_nan(self):
1446-
# GH 31861
1447-
result = DataFrame({"a": ["test"], "b": [np.nan]})
1448-
with tm.assert_produces_warning(FutureWarning, match="incompatible dtype"):
1449-
result.loc[:, "b"] = result.loc[:, "b"].astype("Int64")
1450-
expected = DataFrame({"a": ["test"], "b": array([NA], dtype="Int64")})
1451-
tm.assert_frame_equal(result, expected)

pandas/tests/indexing/test_loc.py

Lines changed: 11 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from collections import namedtuple
44
from datetime import (
5-
date,
65
datetime,
76
time,
87
timedelta,
@@ -16,7 +15,6 @@
1615
from pandas._config import using_pyarrow_string_dtype
1716

1817
from pandas._libs import index as libindex
19-
from pandas.compat.numpy import np_version_gt2
2018
from pandas.errors import IndexingError
2119

2220
import pandas as pd
@@ -379,17 +377,6 @@ def test_loc_setitem_slice(self):
379377
)
380378
tm.assert_frame_equal(df1, expected)
381379

382-
# assigning a new type should get the inferred type
383-
df2 = DataFrame({"a": [0, 1, 1], "b": [100, 200, 300]}, dtype="uint64")
384-
ix = df1["a"] == 1
385-
newb2 = df2.loc[ix, "b"]
386-
with tm.assert_produces_warning(
387-
FutureWarning, match="item of incompatible dtype"
388-
):
389-
df1.loc[ix, "b"] = newb2
390-
expected = DataFrame({"a": [0, 1, 1], "b": [100, 200, 300]}, dtype="uint64")
391-
tm.assert_frame_equal(df2, expected)
392-
393380
def test_loc_setitem_dtype(self):
394381
# GH31340
395382
df = DataFrame({"id": ["A"], "a": [1.2], "b": [0.0], "c": [-2.5]})
@@ -565,62 +552,6 @@ def frame_for_consistency(self):
565552
}
566553
)
567554

568-
@pytest.mark.parametrize(
569-
"val",
570-
[0, np.array(0, dtype=np.int64), np.array([0, 0, 0, 0, 0], dtype=np.int64)],
571-
)
572-
def test_loc_setitem_consistency(self, frame_for_consistency, val):
573-
# GH 6149
574-
# coerce similarly for setitem and loc when rows have a null-slice
575-
expected = DataFrame(
576-
{
577-
"date": Series(0, index=range(5), dtype=np.int64),
578-
"val": Series(range(5), dtype=np.int64),
579-
}
580-
)
581-
df = frame_for_consistency.copy()
582-
with tm.assert_produces_warning(FutureWarning, match="incompatible dtype"):
583-
df.loc[:, "date"] = val
584-
tm.assert_frame_equal(df, expected)
585-
586-
def test_loc_setitem_consistency_dt64_to_str(self, frame_for_consistency):
587-
# GH 6149
588-
# coerce similarly for setitem and loc when rows have a null-slice
589-
590-
expected = DataFrame(
591-
{
592-
"date": Series("foo", index=range(5)),
593-
"val": Series(range(5), dtype=np.int64),
594-
}
595-
)
596-
df = frame_for_consistency.copy()
597-
with tm.assert_produces_warning(FutureWarning, match="incompatible dtype"):
598-
df.loc[:, "date"] = "foo"
599-
tm.assert_frame_equal(df, expected)
600-
601-
def test_loc_setitem_consistency_dt64_to_float(self, frame_for_consistency):
602-
# GH 6149
603-
# coerce similarly for setitem and loc when rows have a null-slice
604-
expected = DataFrame(
605-
{
606-
"date": Series(1.0, index=range(5)),
607-
"val": Series(range(5), dtype=np.int64),
608-
}
609-
)
610-
df = frame_for_consistency.copy()
611-
with tm.assert_produces_warning(FutureWarning, match="incompatible dtype"):
612-
df.loc[:, "date"] = 1.0
613-
tm.assert_frame_equal(df, expected)
614-
615-
def test_loc_setitem_consistency_single_row(self):
616-
# GH 15494
617-
# setting on frame with single row
618-
df = DataFrame({"date": Series([Timestamp("20180101")])})
619-
with tm.assert_produces_warning(FutureWarning, match="incompatible dtype"):
620-
df.loc[:, "date"] = "string"
621-
expected = DataFrame({"date": Series(["string"])})
622-
tm.assert_frame_equal(df, expected)
623-
624555
def test_loc_setitem_consistency_empty(self):
625556
# empty (essentially noops)
626557
# before the enforcement of #45333 in 2.0, the loc.setitem here would
@@ -675,16 +606,16 @@ def test_loc_setitem_consistency_slice_column_len(self):
675606
- df.loc[:, ("Respondent", "StartDate")]
676607
)
677608

678-
# timedelta64[m] -> float, so this cannot be done inplace, so
679-
# no warning
680-
with tm.assert_produces_warning(FutureWarning, match="incompatible dtype"):
681-
df.loc[:, ("Respondent", "Duration")] = df.loc[
682-
:, ("Respondent", "Duration")
683-
] / Timedelta(60_000_000_000)
684-
685609
expected = Series(
686-
[23.0, 12.0, 14.0, 36.0], index=df.index, name=("Respondent", "Duration")
687-
)
610+
[
611+
timedelta(minutes=23),
612+
timedelta(minutes=12),
613+
timedelta(minutes=14),
614+
timedelta(minutes=36),
615+
],
616+
index=df.index,
617+
name=("Respondent", "Duration"),
618+
).astype("timedelta64[s]")
688619
tm.assert_series_equal(df[("Respondent", "Duration")], expected)
689620

690621
@pytest.mark.parametrize("unit", ["Y", "M", "D", "h", "m", "s", "ms", "us"])
@@ -1409,18 +1340,6 @@ def test_loc_setitem_listlike_with_timedelta64index(self, indexer, expected):
14091340

14101341
tm.assert_frame_equal(expected, df)
14111342

1412-
def test_loc_setitem_categorical_values_partial_column_slice(self):
1413-
# Assigning a Category to parts of a int/... column uses the values of
1414-
# the Categorical
1415-
df = DataFrame({"a": [1, 1, 1, 1, 1], "b": list("aaaaa")})
1416-
exp = DataFrame({"a": [1, "b", "b", 1, 1], "b": list("aabba")})
1417-
with tm.assert_produces_warning(
1418-
FutureWarning, match="item of incompatible dtype"
1419-
):
1420-
df.loc[1:2, "a"] = Categorical(["b", "b"], categories=["a", "b"])
1421-
df.loc[2:3, "b"] = Categorical(["b", "b"], categories=["a", "b"])
1422-
tm.assert_frame_equal(df, exp)
1423-
14241343
def test_loc_setitem_single_row_categorical(self, using_infer_string):
14251344
# GH#25495
14261345
df = DataFrame({"Alpha": ["a"], "Numeric": [0]})
@@ -1440,16 +1359,6 @@ def test_loc_setitem_single_row_categorical(self, using_infer_string):
14401359
df["Alpha"] = categories
14411360
tm.assert_series_equal(df["Alpha"], Series(categories, name="Alpha"))
14421361

1443-
def test_loc_setitem_datetime_coercion(self):
1444-
# GH#1048
1445-
df = DataFrame({"c": [Timestamp("2010-10-01")] * 3})
1446-
df.loc[0:1, "c"] = np.datetime64("2008-08-08")
1447-
assert Timestamp("2008-08-08") == df.loc[0, "c"]
1448-
assert Timestamp("2008-08-08") == df.loc[1, "c"]
1449-
with tm.assert_produces_warning(FutureWarning, match="incompatible dtype"):
1450-
df.loc[2, "c"] = date(2005, 5, 5)
1451-
assert Timestamp("2005-05-05").date() == df.loc[2, "c"]
1452-
14531362
@pytest.mark.parametrize("idxer", ["var", ["var"]])
14541363
def test_loc_setitem_datetimeindex_tz(self, idxer, tz_naive_fixture):
14551364
# GH#11365
@@ -1459,11 +1368,8 @@ def test_loc_setitem_datetimeindex_tz(self, idxer, tz_naive_fixture):
14591368
# if result started off with object dtype, then the .loc.__setitem__
14601369
# below would retain object dtype
14611370
result = DataFrame(index=idx, columns=["var"], dtype=np.float64)
1462-
with tm.assert_produces_warning(
1463-
FutureWarning if idxer == "var" else None, match="incompatible dtype"
1464-
):
1465-
# See https://github.com/pandas-dev/pandas/issues/56223
1466-
result.loc[:, idxer] = expected
1371+
# See https://github.com/pandas-dev/pandas/issues/56223
1372+
result.loc[:, ["var"]] = expected
14671373
tm.assert_frame_equal(result, expected)
14681374

14691375
def test_loc_setitem_time_key(self):
@@ -1605,22 +1511,6 @@ def test_loc_setitem_single_column_mixed(self, using_infer_string):
16051511
).values
16061512
tm.assert_almost_equal(df["str"].values, expected)
16071513

1608-
def test_loc_setitem_cast2(self):
1609-
# GH#7704
1610-
# dtype conversion on setting
1611-
df = DataFrame(np.random.default_rng(2).random((30, 3)), columns=tuple("ABC"))
1612-
df["event"] = np.nan
1613-
with tm.assert_produces_warning(
1614-
FutureWarning, match="item of incompatible dtype"
1615-
):
1616-
df.loc[10, "event"] = "foo"
1617-
result = df.dtypes
1618-
expected = Series(
1619-
[np.dtype("float64")] * 3 + [np.dtype("object")],
1620-
index=["A", "B", "C", "event"],
1621-
)
1622-
tm.assert_series_equal(result, expected)
1623-
16241514
def test_loc_setitem_cast3(self):
16251515
# Test that data type is preserved . GH#5782
16261516
df = DataFrame({"one": np.arange(6, dtype=np.int8)})
@@ -2969,26 +2859,6 @@ def test_loc_getitem_nullable_index_with_duplicates():
29692859
tm.assert_series_equal(res, expected)
29702860

29712861

2972-
@pytest.mark.parametrize("value", [300, np.uint16(300), np.int16(300)])
2973-
def test_loc_setitem_uint8_upcast(value):
2974-
# GH#26049
2975-
2976-
df = DataFrame([1, 2, 3, 4], columns=["col1"], dtype="uint8")
2977-
with tm.assert_produces_warning(FutureWarning, match="item of incompatible dtype"):
2978-
df.loc[2, "col1"] = value # value that can't be held in uint8
2979-
2980-
if np_version_gt2 and isinstance(value, np.int16):
2981-
# Note, result type of uint8 + int16 is int16
2982-
# in numpy < 2, though, numpy would inspect the
2983-
# value and see that it could fit in an uint16, resulting in a uint16
2984-
dtype = "int16"
2985-
else:
2986-
dtype = "uint16"
2987-
2988-
expected = DataFrame([1, 2, 300, 4], columns=["col1"], dtype=dtype)
2989-
tm.assert_frame_equal(df, expected)
2990-
2991-
29922862
@pytest.mark.parametrize(
29932863
"fill_val,exp_dtype",
29942864
[

0 commit comments

Comments
 (0)