API: Raise when setting name via level
Closes https://github.com/pandas-dev/pandas/issues/29032

This is extremely ugly, but gets the job done. It's probably worth doing to avoid silently failing, but not sure.

cc @topper-123.
I think it has to be on all index subclasses since they make up the levels of a MultiIndex.  @TomAugspurger , but if it's set on ``Index`` all index subclasses inherit the attribute? Right, since it’s the level of the MI that can’t have its name set, not the MI itself.  My apologies, I've simplified things a bit. I misunderstood what happened to class attributes when the attribute is set on an instance. > This will be removed later, when we feel confident that people have switched idiom, right?

I'm not sure. We can weigh the maintenance cost down the road and remove it if it's burdensome. I'm fine with this as-is.

Spitballing another solution: we could have Index._names be an ndarray for all Index subclasses, with

```
@property
def name(self):
    return self._names[0]     

@name.setter
def name(self, value):
    if np.is_view_or_whatever(self._names):
        raise RuntimeError(...)
    self._names[0] = value
``` this looks fine, butI would consider something slightly different. We could have an attribute defined on Index._parent = None

then set a weakref when it is contained in a MultiIndex. This gives us provenance on where things are coming from. might be useful. Mmm, that's also reasonable. My initial concern is that indexes are potentially shared, so they could have multiple parents? For this purpose it's not a problem since we're creating the Index from scratch, just something to keep in mind going forward. > Mmm, that's also reasonable. My initial concern is that indexes are potentially shared, so they could have multiple parents? For this purpose it's not a problem since we're creating the Index from scratch, just something to keep in mind going forward.

I don’t think we share for a contained Index inside a MultiIndex but not really sure You're right, these levels of a MI are created on the fly.

In theory, a user-action could end up with an Index that's created from the level of a MI

```python
s = pd.Series(index=idx.levels[0])
```

but that probably doesn't affect your proposed "parent" reference.

That implementation is going to be more complex though, since subclasses don't call `Index._simple_new`. Thoughts on waiting till we need it?
 yeah was just an idea i think what u did here is ok
let me have another glance  thanks @TomAugspurger 