Repository: pandas-dev/pandas

Issue:
BUG: Series.dt accessor throws exception after Series.drop when inplace=True
#### Code Sample, a copy-pastable example

```python
import pandas as pd

z = pd.Series(pd.date_range('2018-01-01', periods=100))
z.drop(z[z.dt.weekday >= 4].index, inplace=True)

print(f"Length of z's index is {len(z.index)}, trying to access z.dt.date")
try:
    z.dt.date
except ValueError as e:
    print("Got error", e)

z.reset_index(inplace=True, drop=True)
print(f"Length of z's index is {len(z.index)}, trying to access z.dt.date")
try:
    z.dt.date
except ValueError as e:
    print("Got error", e)
```

yields:

```
Length of z's index is 58, trying to access z.dt.date
Got error Length of passed values is 58, index implies 100
Length of z's index is 58, trying to access z.dt.date
Got error Length of passed values is 58, index implies 100
```

#### Problem description

I don't understand why the code throws an exception and where the error message gets length of 100 when the index has been reset.

#### Expected Output

At least the second `z.dt.date` should not throw.

<details>

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.7.final.0
python-bits: 64
OS: Linux
OS-release: 3.10.0-514.26.2.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.23.4
pytest: 4.0.2
pip: 18.1
setuptools: 40.6.3
Cython: 0.29.2
numpy: 1.15.4
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 7.2.0
sphinx: 1.8.2
patsy: 0.5.1
dateutil: 2.7.5
pytz: 2018.7
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.8
feather: None
matplotlib: 3.0.2
openpyxl: 2.5.12
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: 1.1.2
lxml: 4.2.5
bs4: 4.6.3
html5lib: 1.0.1
sqlalchemy: 1.2.15
pymysql: None
psycopg2: 2.7.6.1 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
</details>


Discussion:
Happens specifically when `inplace=True`

```
In [8]: z = pd.Series(pd.date_range('2018-01-01', periods=7))
   ...: z = z.drop(z[z.dt.weekday >= 4].index)

In [9]: z.dt.date
Out[9]:
0    2018-01-01
1    2018-01-02
2    2018-01-03
3    2018-01-04
dtype: object

In [10]: z = pd.Series(pd.date_range('2018-01-01', periods=7))
    ...: z.drop(z[z.dt.weekday >= 4].index, inplace=True)

In [11]: z.dt.date
ValueError: Length of passed values is 4, index implies 7
```

Resolving patch:
diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py
--- a/pandas/core/indexes/accessors.py
+++ b/pandas/core/indexes/accessors.py
@@ -27,7 +27,6 @@ def __init__(self, data, orig):
         self._parent = data
         self.orig = orig
         self.name = getattr(data, 'name', None)
-        self.index = getattr(data, 'index', None)
         self._freeze()
 
     def _get_values(self):
@@ -71,8 +70,7 @@ def _delegate_property_get(self, name):
             result = take_1d(result, self.orig.cat.codes)
             index = self.orig.index
         else:
-            index = self.index
-
+            index = self._parent.index
         # return the result as a Series, which is by definition a copy
         result = Series(result, index=index, name=self.name)
 
@@ -98,7 +96,7 @@ def _delegate_method(self, name, *args, **kwargs):
         if not is_list_like(result):
             return result
 
-        result = Series(result, index=self.index, name=self.name)
+        result = Series(result, index=self._parent.index, name=self.name)
 
         # setting this object will show a SettingWithCopyWarning/Error
         result._is_copy = ("modifications to a method of a datetimelike "
@@ -261,7 +259,7 @@ def components(self):
         3     0      0        0        3             0             0            0
         4     0      0        0        4             0             0            0
         """  # noqa: E501
-        return self._get_values().components.set_index(self.index)
+        return self._get_values().components.set_index(self._parent.index)
 
     @property
     def freq(self):


Test patch:
diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py
--- a/pandas/tests/plotting/test_series.py
+++ b/pandas/tests/plotting/test_series.py
@@ -890,3 +890,15 @@ def test_misc_bindings(self, mock):
             assert s.plot.lag() == 2
             assert s.plot.autocorrelation() == 2
             assert s.plot.bootstrap() == 2
+
+    @pytest.mark.xfail
+    def test_plot_accessor_updates_on_inplace(self):
+        s = Series([1, 2, 3, 4])
+        _, ax = self.plt.subplots()
+        ax = s.plot(ax=ax)
+        before = ax.xaxis.get_ticklocs()
+
+        s.drop([0, 1], inplace=True)
+        _, ax = self.plt.subplots()
+        after = ax.xaxis.get_ticklocs()
+        tm.assert_numpy_array_equal(before, after)
diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py
--- a/pandas/tests/series/test_api.py
+++ b/pandas/tests/series/test_api.py
@@ -204,6 +204,11 @@ def test_from_array_deprecated(self):
         with tm.assert_produces_warning(FutureWarning):
             self.series_klass.from_array([1, 2, 3])
 
+    def test_sparse_accessor_updates_on_inplace(self):
+        s = pd.Series([1, 1, 2, 3], dtype="Sparse[int]")
+        s.drop([0, 1], inplace=True)
+        assert s.sparse.density == 1.0
+
 
 class TestSeriesMisc(TestData, SharedWithSparse):
 
@@ -447,6 +452,11 @@ def f(x):
         exp = Series([], dtype='float64', index=Index([], dtype='float64'))
         tm.assert_series_equal(result, exp)
 
+    def test_str_accessor_updates_on_inplace(self):
+        s = pd.Series(list('abc'))
+        s.drop([0], inplace=True)
+        assert len(s.str.lower()) == 2
+
     def test_str_attribute(self):
         # GH9068
         methods = ['strip', 'rstrip', 'lstrip']
@@ -535,6 +545,12 @@ def test_cat_accessor_no_new_attributes(self):
                            match="You cannot add any new attribute"):
             c.cat.xlabel = "a"
 
+    def test_cat_accessor_updates_on_inplace(self):
+        s = Series(list('abc')).astype('category')
+        s.drop(0, inplace=True)
+        s.cat.remove_unused_categories(inplace=True)
+        assert len(s.cat.categories) == 2
+
     def test_categorical_delegations(self):
 
         # invalid accessor
diff --git a/pandas/tests/series/test_datetime_values.py b/pandas/tests/series/test_datetime_values.py
--- a/pandas/tests/series/test_datetime_values.py
+++ b/pandas/tests/series/test_datetime_values.py
@@ -485,6 +485,13 @@ def test_dt_accessor_invalid(self, ser):
             ser.dt
         assert not hasattr(ser, 'dt')
 
+    def test_dt_accessor_updates_on_inplace(self):
+        s = Series(pd.date_range('2018-01-01', periods=10))
+        s[2] = None
+        s.fillna(pd.Timestamp('2018-01-01'), inplace=True)
+        result = s.dt.date
+        assert result[0] == result[2]
+
     def test_between(self):
         s = Series(bdate_range('1/1/2000', periods=20).astype(object))
         s[::2] = np.nan