Parse IntervalArray and IntervalIndex from strings
State: closed

Currently, when saving a DataFrame with an IntervalIndex as a CSV, there is no easy way to parse it again. With this PR, class methods are introduced to handle this:

```python
import tempfile

import numpy as np
import pandas as pd

# Create a DataFrame with an IntervalIndex
df = pd.DataFrame(data=[1, 2, 3], index=pd.IntervalIndex.from_breaks([2., 3., 4., 5.]))

# Create a temporary directory to save the csv in
temp_dir = tempfile.TemporaryDirectory()
df.to_csv(temp_dir.name + 'df.csv')

print(df)

# Read the DataFrame containing the IntervalIndex column
df2 = pd.read_csv(temp_dir.name + 'df.csv')

# Convert the column to an IntervalIndex
df2.index = pd.IntervalIndex.from_strings(df2.iloc[:, 0])
df2.drop(columns=df2.columns[0], inplace=True)

print(df2)

# Validate that the original and parsed indices are the same
assert np.array_equal(df.index, df2.index)

```

```
            0
(2.0, 3.0]  1
(3.0, 4.0]  2
(4.0, 5.0]  3
            0
(2.0, 3.0]  1
(3.0, 4.0]  2
(4.0, 5.0]  3
```

As can be seen in the tests, the conversion supports each valid dtype of an Interval and raises descriptive exceptions if it fails.

- [X] closes #23595
- [X] tests added / passed
- [X] Ensure all linting tests pass, see [here](https://pandas.pydata.org/pandas-docs/dev/development/contributing.html#code-standards) for how to run them
- [ ] whatsnew entry


Labels:
name: Enhancement
name: IO CSV
description: read_csv, to_csv
name: Interval
description: Interval data type

Comments:
MyPy misunderstood the type of a list because I mixed callable types and functions. I explicitly annotated a list before looping over it this time, so MyPy should be happier now!

Also, I fixed the doctest.
@simonjayhawkins  or others, could we trigger the workflows to see that everything works well now?
Thank you for the feedback, @jreback! I implemented all comments that I understood. There was just one that I did not catch your meaning of:
> this is very fixed to a single closed type - is there a reason?

Please let me know if this is now solved or where I can read more about what you mean.

Also, I had some issues with the CI, so I pulled from upstream. We'll see what happens this time..
Hey! All checks passed a week ago except one that timed out after 60 minutes, so I tried merging from upstream again. Can we try the CI again now, @jreback @simonjayhawkins or others?
Thanks for the feedback, @jreback! I think I solved all of your requests this time.
I have implemented all fixes a few weeks ago and it passes the checks!

What's the next step, @jreback @simonjayhawkins ?
This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.
This pull request is still relevant and I still request a new review.
> This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.

I wish for this to stay open.
looked ok the last time. can you address open items and merge master;; ping on green
> looked ok the last time. can you address open items and merge master;; ping on green

Hi @jreback. Thanks for all the good comments! Field season ends this week so I'll try to get it fixed next week.
Hi again @jreback  and others! Sorry for the delay with the fixes. The comments I got led to significant improvements, specifically with the added support of all the closed types.

It seems CI may need to be rerun (`Posix / pytest (actions-39-slow.yaml, slow) (pull_request)` fails saying `Could not find conda environment: pandas-dev`).

I am available quicker from now on regarding potential other fixes.

Thanks again for the help!
can you merge master
@mntss can you address comments and merge master (i don't think we had much left)
@jreback  perhaps there are others who can help? There's no rush for me anymore, since I just implemented these functionalities separately for the project I'm working on, but I think it would be a great feature for more people than I!

To recapitulate, everything worked quite fine, but the renaming of some methods (e.g. `_from_sequence_of_strings`) led to errors that I simply don't understand. Either we revert these changes, or someone more knowledgeable than I chimes in!
Thanks for the PR, but it appears to have gone stale. If you or anyone else would like to pick this PR back up we can reopen, closing for now.