DOC: Fix error in pandas.Index.to_series
State: closed

- [ ] closes #xxxx
- [ ] tests added / passed
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

Related to #27977. 

output of `python scripts/validate_docstrings.py pandas.Index.to_series`:
```
################################################################################
################################## Validation ##################################
################################################################################
```

Notes:
While working with the documentation, I noticed that index parameter in `pandas.Index.to_series` has different behaviour with `pandas.Index.to_frame`. You can't specify index parameter to False in `pandas.Index.to_series` to achieve the same index result with `pandas.Index.to_frame`. Is this intentional?



Labels:
name: Docs
name: Index
description: Related to the Index class or subclasses

Comments:
> 
> 
> Nice, thanks! Examples are always helpful, IMO - as it says in the [docstring guide](https://pandas.pydata.org/docs/development/contributing_docstring.html),
> 
> > As often, people understand concepts better with examples, than with accurate explanations.

Sure, here's the minimal example

```python
In [1]: import pandas as pd

In [2]: idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal')

In [3]: idx.to_frame(index=False)
Out[3]: 
  animal
0    Ant
1   Bear
2    Cow

In [4]: idx.to_series(index=False)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-bc071128e429> in <module>
----> 1 idx.to_series(index=False)

E:\farhan-reynaldo\pandas-farhanreynaldo\pandas\core\indexes\base.py in to_series(self, index, name)
   1053             name = self.name
   1054
-> 1055         return Series(self.values.copy(), index=index, name=name)
   1056
   1057     def to_frame(self, index: bool = True, name=None):

E:\farhan-reynaldo\pandas-farhanreynaldo\pandas\core\series.py in __init__(self, data, index, dtype, name, copy, fastpath)
    239
    240             if index is not None:
--> 241                 index = ensure_index(index)
    242
    243             if data is None:

E:\farhan-reynaldo\pandas-farhanreynaldo\pandas\core\indexes\base.py in ensure_index(index_like, copy)
   5557             index_like = copy_func(index_like)
   5558
-> 5559     return Index(index_like)
   5560
   5561

E:\farhan-reynaldo\pandas-farhanreynaldo\pandas\core\indexes\base.py in __new__(cls, data, dtype, copy, name, tupleize_cols, **kwargs)
    403
    404         elif data is None or is_scalar(data):
--> 405             raise cls._scalar_data_error(data)
    406         elif hasattr(data, "__array__"):
    407             return Index(np.asarray(data), dtype=dtype, copy=copy, name=name, **kwargs)

TypeError: Index(...) must be called with a collection of some kind, False was passed
```

I expect the `pandas.Index.to_series` would also produce default index like in `pandas.Index.to_frame`.
Sorry, I might have been unclear - what I meant was, "I like your PR because you've added examples" :)
> 
> 
> Sorry, I might have been unclear - what I meant was, "I like your PR because you've added examples" :)

Oops sorry for the misunderstanding haha, I really appreciate the kind words, @MarcoGorelli.
> I expect the pandas.Index.to_series would also produce default index like in pandas.Index.to_frame.

I hadn't come across this before, but I think I would have expected similar behaviour - could you please open a new issue (if it hasn't been posted before) with the code you just gave?
> 
> 
> > I expect the pandas.Index.to_series would also produce default index like in pandas.Index.to_frame.
> 
> I hadn't come across this before, but I think I would have expected similar behaviour - could you please open a new issue (if it hasn't been posted before) with the code you just gave?

Sure, I'll open a new issue if it hasn't been posted.
thanks @farhanreynaldo 

you can open a new issue for these differences in behavior on Series/DataFrame, reference this issue.
> thanks @farhanreynaldo
> 
> you can open a new issue for these differences in behavior on Series/DataFrame, reference this issue.

just for reference, they opened it here #34351