Repository: pandas-dev/pandas

Issue:
Silently ignored kwargs in Index.to_series

```
>>> idx = pd.date_range('1994-10-06', freq='D', periods=4)
>>> idx.day.to_series(index=idx)
>>> idx.day.to_series(index=idx)
6    6
7    7
8    8
9    9
```

Expected:

```
>>> idx.day.to_series(index=idx)
1994-10-06    6
1994-10-07    7
1994-10-08    8
1994-10-09    9
```

Looks like Index.to_series takes **kwargs but then ignores them.  Should be an easy fix; would be nice to systematically track down other places this might happen.


Discussion:
yeah looks like old/typo. should be removable.
I'm looking into this issue.

Fixed the `Index.to_series(**kwargs)` bug and added tests to common.py which also contains the original test for this method.

None of the tests in this module are being run:

```console
$ pytest pandas/tests/indexes/common.py
================================= test session starts ==================================
platform darwin -- Python 3.6.1, pytest-3.1.2, py-1.4.34, pluggy-0.4.0
rootdir: /Users/alysivji/Documents/siv-dev/projects/open-source/pandas, inifile: setup.cfg
plugins: xdist-1.17.1
collected 0 items

============================= no tests ran in 0.01 seconds =============================
```

Where should I be writing my tests?

Note: same bug is also showing up in Index.to_frame(), where index=True is a default kwarg.

```
>>> import pandas as pd
>>> idx = pd.date_range('1994-10-06', freq='D', periods=4)
>>> idx.day.to_frame()
   0
6  6
7  7
8  8
9  9
```
common is included in all the subclasses

you can add them there

Resolving patch:
diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py
--- a/pandas/core/indexes/base.py
+++ b/pandas/core/indexes/base.py
@@ -983,20 +983,32 @@ def _format_attrs(self):
             attrs.append(('length', len(self)))
         return attrs
 
-    def to_series(self, **kwargs):
+    def to_series(self, index=None, name=None):
         """
         Create a Series with both index and values equal to the index keys
         useful with map for returning an indexer based on an index
 
+        Parameters
+        ----------
+        index : Index, optional
+            index of resulting Series. If None, defaults to original index
+        name : string, optional
+            name of resulting Series. If None, defaults to name of original
+            index
+
         Returns
         -------
         Series : dtype will be based on the type of the Index values.
         """
 
         from pandas import Series
-        return Series(self._to_embed(),
-                      index=self._shallow_copy(),
-                      name=self.name)
+
+        if index is None:
+            index = self._shallow_copy()
+        if name is None:
+            name = self.name
+
+        return Series(self._to_embed(), index=index, name=name)
 
     def to_frame(self, index=True):
         """
diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py
--- a/pandas/core/indexes/datetimes.py
+++ b/pandas/core/indexes/datetimes.py
@@ -927,7 +927,7 @@ def _get_time_micros(self):
             values = self._local_timestamps()
         return fields.get_time_micros(values)
 
-    def to_series(self, keep_tz=False):
+    def to_series(self, keep_tz=False, index=None, name=None):
         """
         Create a Series with both index and values equal to the index keys
         useful with map for returning an indexer based on an index
@@ -949,15 +949,24 @@ def to_series(self, keep_tz=False):
 
               Series will have a datetime64[ns] dtype. TZ aware
               objects will have the tz removed.
+        index : Index, optional
+            index of resulting Series. If None, defaults to original index
+        name : string, optional
+            name of resulting Series. If None, defaults to name of original
+            index
 
         Returns
         -------
         Series
         """
         from pandas import Series
-        return Series(self._to_embed(keep_tz),
-                      index=self._shallow_copy(),
-                      name=self.name)
+
+        if index is None:
+            index = self._shallow_copy()
+        if name is None:
+            name = self.name
+
+        return Series(self._to_embed(keep_tz), index=index, name=name)
 
     def _to_embed(self, keep_tz=False, dtype=None):
         """


Test patch:
diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py
--- a/pandas/tests/indexes/common.py
+++ b/pandas/tests/indexes/common.py
@@ -50,6 +50,25 @@ def test_to_series(self):
         assert s.index is not idx
         assert s.name == idx.name
 
+    def test_to_series_with_arguments(self):
+        # GH18699
+
+        # index kwarg
+        idx = self.create_index()
+        s = idx.to_series(index=idx)
+
+        assert s.values is not idx.values
+        assert s.index is idx
+        assert s.name == idx.name
+
+        # name kwarg
+        idx = self.create_index()
+        s = idx.to_series(name='__test')
+
+        assert s.values is not idx.values
+        assert s.index is not idx
+        assert s.name != idx.name
+
     def test_to_frame(self):
         # see gh-15230
         idx = self.create_index()