Skip to content

Updating repo #1

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
merged 2 commits into from
Dec 26, 2020
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
1 change: 0 additions & 1 deletion doc/source/whatsnew/v1.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ Deprecations
- Deprecated indexing :class:`DataFrame` rows with a single datetime-like string as ``df[string]``
(given the ambiguity whether it is indexing the rows or selecting a column), use
``df.loc[string]`` instead (:issue:`36179`)
- Deprecated casting an object-dtype index of ``datetime`` objects to :class:`.DatetimeIndex` in the :class:`Series` constructor (:issue:`23598`)
- Deprecated :meth:`Index.is_all_dates` (:issue:`27744`)
- The default value of ``regex`` for :meth:`Series.str.replace` will change from ``True`` to ``False`` in a future release. In addition, single character regular expressions will *not* be treated as literal strings when ``regex=True`` is set. (:issue:`24804`)
- Deprecated automatic alignment on comparison operations between :class:`DataFrame` and :class:`Series`, do ``frame, ser = frame.align(ser, axis=1, copy=False)`` before e.g. ``frame == ser`` (:issue:`28759`)
Expand Down
6 changes: 0 additions & 6 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9467,12 +9467,6 @@ def truncate(
# if we have a date index, convert to dates, otherwise
# treat like a slice
if ax._is_all_dates:
if is_object_dtype(ax.dtype):
warnings.warn(
"Treating object-dtype Index of date objects as DatetimeIndex "
"is deprecated, will be removed in a future version.",
FutureWarning,
)
from pandas.core.tools.datetimes import to_datetime

before = to_datetime(before)
Expand Down
12 changes: 0 additions & 12 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
find_common_type,
infer_dtype_from,
infer_dtype_from_scalar,
maybe_box_datetimelike,
maybe_downcast_numeric,
maybe_downcast_to_dtype,
maybe_infer_dtype_type,
Expand Down Expand Up @@ -746,11 +745,6 @@ def replace(
return [self] if inplace else [self.copy()]

values = self.values
if lib.is_scalar(to_replace) and isinstance(values, np.ndarray):
# The only non-DatetimeLike class that also has a non-trivial
# try_coerce_args is ObjectBlock, but that overrides replace,
# so does not get here.
to_replace = convert_scalar_for_putitemlike(to_replace, values.dtype)

mask = missing.mask_missing(values, to_replace)
if not mask.any():
Expand Down Expand Up @@ -845,7 +839,6 @@ def comp(s: Scalar, mask: np.ndarray, regex: bool = False) -> np.ndarray:
if isna(s):
return ~mask

s = maybe_box_datetimelike(s)
return compare_or_regex_search(self.values, s, regex, mask)

if self.is_object:
Expand Down Expand Up @@ -919,8 +912,6 @@ def setitem(self, indexer, value):
arr = self.array_values().T
arr[indexer] = value
return self
elif lib.is_scalar(value):
value = convert_scalar_for_putitemlike(value, values.dtype)

else:
# current dtype cannot store value, coerce to common dtype
Expand Down Expand Up @@ -1067,9 +1058,6 @@ def putmask(self, mask, new, axis: int = 0) -> List["Block"]:
arr.putmask(mask, new)
return [self]

if lib.is_scalar(new):
new = convert_scalar_for_putitemlike(new, self.values.dtype)

if transpose:
new_values = new_values.T

Expand Down
7 changes: 0 additions & 7 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,6 @@ def _set_axis(self, axis: int, labels, fastpath: bool = False) -> None:
# need to set here because we changed the index
if fastpath:
self._mgr.set_axis(axis, labels)
warnings.warn(
"Automatically casting object-dtype Index of datetimes to "
"DatetimeIndex is deprecated and will be removed in a "
"future version. Explicitly cast to DatetimeIndex instead.",
FutureWarning,
stacklevel=3,
)
except (tslibs.OutOfBoundsDatetime, ValueError):
# labels may exceeds datetime bounds,
# or not be a DatetimeIndex
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,7 @@ def test_string_slice(self):
df["2011"]

with pytest.raises(KeyError, match="'2011'"):
with tm.assert_produces_warning(FutureWarning):
# This does an is_all_dates check
df.loc["2011", 0]
df.loc["2011", 0]

df = DataFrame()
assert not df.index._is_all_dates
Expand Down
14 changes: 5 additions & 9 deletions pandas/tests/io/pytables/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -2441,17 +2441,13 @@ def test_series(self, setup_path):
ts = tm.makeTimeSeries()
self._check_roundtrip(ts, tm.assert_series_equal, path=setup_path)

with tm.assert_produces_warning(FutureWarning):
# auto-casting object->DatetimeIndex deprecated
ts2 = Series(ts.index, Index(ts.index, dtype=object))
ts2 = Series(ts.index, Index(ts.index, dtype=object))
self._check_roundtrip(ts2, tm.assert_series_equal, path=setup_path)

with tm.assert_produces_warning(FutureWarning):
# auto-casting object->DatetimeIndex deprecated
ts3 = Series(
ts.values, Index(np.asarray(ts.index, dtype=object), dtype=object)
)
self._check_roundtrip(ts3, tm.assert_series_equal, path=setup_path)
ts3 = Series(ts.values, Index(np.asarray(ts.index, dtype=object), dtype=object))
self._check_roundtrip(
ts3, tm.assert_series_equal, path=setup_path, check_index_type=False
)

def test_float_index(self, setup_path):

Expand Down
26 changes: 6 additions & 20 deletions pandas/tests/plotting/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,9 @@ def test_irreg_hf(self):
_, ax = self.plt.subplots()
df2 = df.copy()
df2.index = df.index.astype(object)
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
# This warning will be emitted
# pandas/core/frame.py:3216:
# FutureWarning: Automatically casting object-dtype Index of datetimes
# to DatetimeIndex is deprecated and will be removed in a future version.
# Explicitly cast to DatetimeIndex instead.
# return klass(values, index=self.index, name=name, fastpath=True)
df2.plot(ax=ax)
diffs = Series(ax.get_lines()[0].get_xydata()[:, 0]).diff()
assert (np.fabs(diffs[1:] - sec) < 1e-8).all()
df2.plot(ax=ax)
diffs = Series(ax.get_lines()[0].get_xydata()[:, 0]).diff()
assert (np.fabs(diffs[1:] - sec) < 1e-8).all()

def test_irregular_datetime64_repr_bug(self):
ser = tm.makeTimeSeries()
Expand Down Expand Up @@ -997,16 +990,9 @@ def test_irreg_dtypes(self):
# np.datetime64
idx = date_range("1/1/2000", periods=10)
idx = idx[[0, 2, 5, 9]].astype(object)
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
# This warning will be emitted
# pandas/core/frame.py:3216:
# FutureWarning: Automatically casting object-dtype Index of datetimes
# to DatetimeIndex is deprecated and will be removed in a future version.
# Explicitly cast to DatetimeIndex instead.
# return klass(values, index=self.index, name=name, fastpath=True)
df = DataFrame(np.random.randn(len(idx), 3), idx)
_, ax = self.plt.subplots()
_check_plot_works(df.plot, ax=ax)
df = DataFrame(np.random.randn(len(idx), 3), idx)
_, ax = self.plt.subplots()
_check_plot_works(df.plot, ax=ax)

def test_time(self):
t = datetime(1, 1, 1, 3, 30, 0)
Expand Down
57 changes: 35 additions & 22 deletions pandas/tests/series/methods/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def test_fillna_downcast(self):
expected = Series([1, 0])
tm.assert_series_equal(result, expected)

def test_timedelta_fillna(self):
def test_timedelta_fillna(self, frame_or_series):
# GH#3371
ser = Series(
[
Expand All @@ -188,9 +188,10 @@ def test_timedelta_fillna(self):
]
)
td = ser.diff()
obj = frame_or_series(td)

# reg fillna
result = td.fillna(Timedelta(seconds=0))
result = obj.fillna(Timedelta(seconds=0))
expected = Series(
[
timedelta(0),
Expand All @@ -199,13 +200,14 @@ def test_timedelta_fillna(self):
timedelta(days=1, seconds=9 * 3600 + 60 + 1),
]
)
tm.assert_series_equal(result, expected)
expected = frame_or_series(expected)
tm.assert_equal(result, expected)

# interpreted as seconds, deprecated
with pytest.raises(TypeError, match="Passing integers to fillna"):
td.fillna(1)
obj.fillna(1)

result = td.fillna(Timedelta(seconds=1))
result = obj.fillna(Timedelta(seconds=1))
expected = Series(
[
timedelta(seconds=1),
Expand All @@ -214,9 +216,10 @@ def test_timedelta_fillna(self):
timedelta(days=1, seconds=9 * 3600 + 60 + 1),
]
)
tm.assert_series_equal(result, expected)
expected = frame_or_series(expected)
tm.assert_equal(result, expected)

result = td.fillna(timedelta(days=1, seconds=1))
result = obj.fillna(timedelta(days=1, seconds=1))
expected = Series(
[
timedelta(days=1, seconds=1),
Expand All @@ -225,9 +228,10 @@ def test_timedelta_fillna(self):
timedelta(days=1, seconds=9 * 3600 + 60 + 1),
]
)
tm.assert_series_equal(result, expected)
expected = frame_or_series(expected)
tm.assert_equal(result, expected)

result = td.fillna(np.timedelta64(int(1e9)))
result = obj.fillna(np.timedelta64(int(1e9)))
expected = Series(
[
timedelta(seconds=1),
Expand All @@ -236,9 +240,10 @@ def test_timedelta_fillna(self):
timedelta(days=1, seconds=9 * 3600 + 60 + 1),
]
)
tm.assert_series_equal(result, expected)
expected = frame_or_series(expected)
tm.assert_equal(result, expected)

result = td.fillna(NaT)
result = obj.fillna(NaT)
expected = Series(
[
NaT,
Expand All @@ -248,21 +253,27 @@ def test_timedelta_fillna(self):
],
dtype="m8[ns]",
)
tm.assert_series_equal(result, expected)
expected = frame_or_series(expected)
tm.assert_equal(result, expected)

# ffill
td[2] = np.nan
result = td.ffill()
obj = frame_or_series(td)
result = obj.ffill()
expected = td.fillna(Timedelta(seconds=0))
expected[0] = np.nan
tm.assert_series_equal(result, expected)
expected = frame_or_series(expected)

tm.assert_equal(result, expected)

# bfill
td[2] = np.nan
result = td.bfill()
obj = frame_or_series(td)
result = obj.bfill()
expected = td.fillna(Timedelta(seconds=0))
expected[2] = timedelta(days=1, seconds=9 * 3600 + 60 + 1)
tm.assert_series_equal(result, expected)
expected = frame_or_series(expected)
tm.assert_equal(result, expected)

def test_datetime64_fillna(self):

Expand Down Expand Up @@ -553,7 +564,7 @@ def test_fillna_period(self):
tm.assert_series_equal(res, exp)
assert res.dtype == "Period[M]"

def test_fillna_dt64_timestamp(self):
def test_fillna_dt64_timestamp(self, frame_or_series):
ser = Series(
[
Timestamp("20130101"),
Expand All @@ -563,9 +574,10 @@ def test_fillna_dt64_timestamp(self):
]
)
ser[2] = np.nan
obj = frame_or_series(ser)

# reg fillna
result = ser.fillna(Timestamp("20130104"))
result = obj.fillna(Timestamp("20130104"))
expected = Series(
[
Timestamp("20130101"),
Expand All @@ -574,11 +586,12 @@ def test_fillna_dt64_timestamp(self):
Timestamp("20130103 9:01:01"),
]
)
tm.assert_series_equal(result, expected)
expected = frame_or_series(expected)
tm.assert_equal(result, expected)

result = ser.fillna(NaT)
expected = ser
tm.assert_series_equal(result, expected)
result = obj.fillna(NaT)
expected = obj
tm.assert_equal(result, expected)

def test_fillna_dt64_non_nao(self):
# GH#27419
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1623,8 +1623,7 @@ def test_constructor_infer_index_tz(self):
class TestSeriesConstructorIndexCoercion:
def test_series_constructor_datetimelike_index_coercion(self):
idx = tm.makeDateIndex(10000)
with tm.assert_produces_warning(FutureWarning):
ser = Series(np.random.randn(len(idx)), idx.astype(object))
ser = Series(np.random.randn(len(idx)), idx.astype(object))
with tm.assert_produces_warning(FutureWarning):
assert ser.index.is_all_dates
assert isinstance(ser.index, DatetimeIndex)
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/series/test_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ def test_timeseries_repr_object_dtype(self):
index = Index(
[datetime(2000, 1, 1) + timedelta(i) for i in range(1000)], dtype=object
)
with tm.assert_produces_warning(FutureWarning):
# Index.is_all_dates deprecated
ts = Series(np.random.randn(len(index)), index)
ts = Series(np.random.randn(len(index)), index)
repr(ts)

ts = tm.makeTimeSeries(1000)
Expand Down
34 changes: 14 additions & 20 deletions pandas/tests/window/moments/test_moments_rolling_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,13 @@ def test_center_reindex_series(raw, series):
s = [f"x{x:d}" for x in range(12)]
minp = 10

warn = None if raw else FutureWarning
with tm.assert_produces_warning(warn, check_stacklevel=False):
# GH#36697 is_all_dates deprecated
series_xp = (
series.reindex(list(series.index) + s)
.rolling(window=25, min_periods=minp)
.apply(f, raw=raw)
.shift(-12)
.reindex(series.index)
)
series_xp = (
series.reindex(list(series.index) + s)
.rolling(window=25, min_periods=minp)
.apply(f, raw=raw)
.shift(-12)
.reindex(series.index)
)
series_rs = series.rolling(window=25, min_periods=minp, center=True).apply(
f, raw=raw
)
Expand All @@ -143,15 +140,12 @@ def test_center_reindex_frame(raw, frame):
s = [f"x{x:d}" for x in range(12)]
minp = 10

warn = None if raw else FutureWarning
with tm.assert_produces_warning(warn, check_stacklevel=False):
# GH#36697 is_all_dates deprecated
frame_xp = (
frame.reindex(list(frame.index) + s)
.rolling(window=25, min_periods=minp)
.apply(f, raw=raw)
.shift(-12)
.reindex(frame.index)
)
frame_xp = (
frame.reindex(list(frame.index) + s)
.rolling(window=25, min_periods=minp)
.apply(f, raw=raw)
.shift(-12)
.reindex(frame.index)
)
frame_rs = frame.rolling(window=25, min_periods=minp, center=True).apply(f, raw=raw)
tm.assert_frame_equal(frame_xp, frame_rs)