Repository: mwouts/itables

Issue:
Categorical index are sorted in the alphabetical order
Should be the categories order instead

Discussion:
codecov-commenter: # [Codecov](https://codecov.io/gh/mwouts/itables/pull/137?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marc+Wouts) Report
> Merging [#137](https://codecov.io/gh/mwouts/itables/pull/137?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marc+Wouts) (b5cef3a) into [main](https://codecov.io/gh/mwouts/itables/commit/d28ca99eb16469bdf595f46828fbcc5622effb54?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marc+Wouts) (d28ca99) will **decrease** coverage by `0.42%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##             main     #137      +/-   ##
==========================================
- Coverage   96.12%   95.70%   -0.43%     
==========================================
  Files          22       22              
  Lines         645      628      -17     
==========================================
- Hits          620      601      -19     
- Misses         25       27       +2     
```


| [Impacted Files](https://codecov.io/gh/mwouts/itables/pull/137?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marc+Wouts) | Coverage Δ | |
|---|---|---|
| [itables/javascript.py](https://codecov.io/gh/mwouts/itables/pull/137/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marc+Wouts#diff-aXRhYmxlcy9qYXZhc2NyaXB0LnB5) | `92.81% <100.00%> (-0.27%)` | :arrow_down: |
| [itables/sample\_dfs.py](https://codecov.io/gh/mwouts/itables/pull/137/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marc+Wouts#diff-aXRhYmxlcy9zYW1wbGVfZGZzLnB5) | `98.78% <100.00%> (-1.22%)` | :arrow_down: |
| [tests/test\_sample\_dfs.py](https://codecov.io/gh/mwouts/itables/pull/137/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marc+Wouts#diff-dGVzdHMvdGVzdF9zYW1wbGVfZGZzLnB5) | `100.00% <100.00%> (ø)` | |
| [tests/test\_update\_samples.py](https://codecov.io/gh/mwouts/itables/pull/137/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marc+Wouts#diff-dGVzdHMvdGVzdF91cGRhdGVfc2FtcGxlcy5weQ==) | `81.25% <0.00%> (-1.11%)` | :arrow_down: |
| [itables/options.py](https://codecov.io/gh/mwouts/itables/pull/137/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marc+Wouts#diff-aXRhYmxlcy9vcHRpb25zLnB5) | `100.00% <0.00%> (ø)` | |
| [tests/test\_changelog.py](https://codecov.io/gh/mwouts/itables/pull/137/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marc+Wouts#diff-dGVzdHMvdGVzdF9jaGFuZ2Vsb2cucHk=) | `100.00% <0.00%> (ø)` | |
| [tests/test\_downsample.py](https://codecov.io/gh/mwouts/itables/pull/137/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marc+Wouts#diff-dGVzdHMvdGVzdF9kb3duc2FtcGxlLnB5) | `100.00% <0.00%> (ø)` | |
| [tests/test\_json\_dumps.py](https://codecov.io/gh/mwouts/itables/pull/137/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marc+Wouts#diff-dGVzdHMvdGVzdF9qc29uX2R1bXBzLnB5) | `100.00% <0.00%> (ø)` | |
| ... and [4 more](https://codecov.io/gh/mwouts/itables/pull/137/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marc+Wouts) | |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marc+Wouts)

mwouts: I'll take #138 instead
mwouts: Finally I'll just remove the default or
mwouts: Finally I'll take the sample dfs from this PR

Patch:
diff --git a/docs/sample_dataframes.md b/docs/sample_dataframes.md
index 6b92dc4..7bcb355 100644
--- a/docs/sample_dataframes.md
+++ b/docs/sample_dataframes.md
@@ -78,6 +78,18 @@ show(dict_of_test_dfs["time"])
 show(dict_of_test_dfs["object"])
 ```
 
+## ordered_categories
+
+```{code-cell}
+show(dict_of_test_dfs["ordered_categories"])
+```
+
+## ordered_categories_in_multiindex
+
+```{code-cell}
+show(dict_of_test_dfs["ordered_categories_in_multiindex"])
+```
+
 ## multiindex
 
 ```{code-cell}
diff --git a/itables/sample_dfs.py b/itables/sample_dfs.py
index c717eb5..997ac01 100644
--- a/itables/sample_dfs.py
+++ b/itables/sample_dfs.py
@@ -129,6 +129,24 @@ def get_dict_of_test_dfs(N=100, M=100):
         "date_range": pd.DataFrame(
             {"timestamps": pd.date_range("now", periods=5, freq="S")}
         ),
+        "ordered_categories": pd.DataFrame(
+            {"int": np.arange(4)},
+            index=pd.CategoricalIndex(
+                ["first", "second", "third", "fourth"],
+                categories=["first", "second", "third", "fourth"],
+                ordered=True,
+                name="categorical_index",
+            ),
+        ),
+        "ordered_categories_in_multiindex": pd.DataFrame(
+            {"int": np.arange(4), "integer_index": np.arange(4)},
+            index=pd.CategoricalIndex(
+                ["first", "second", "third", "fourth"],
+                categories=["first", "second", "third", "fourth"],
+                ordered=True,
+                name="categorical_index",
+            ),
+        ).set_index("integer_index", append=True),
         "object": pd.DataFrame(
             {"dict": [{"a": 1}, {"b": 2, "c": 3}], "list": [["a"], [1, 2]]}
         ),


Test patch:
diff --git a/tests/test_sample_dfs.py b/tests/test_sample_dfs.py
index fb8ec1a..c888acf 100644
--- a/tests/test_sample_dfs.py
+++ b/tests/test_sample_dfs.py
@@ -53,6 +53,12 @@ def test_show_test_dfs(df_name, df):
     show(df)
 
 
+def test_ordered_categories():
+    df = get_dict_of_test_dfs()["ordered_categories"]
+    assert df.index.is_monotonic_increasing
+    assert df["int"].is_monotonic_increasing
+
+
 @pytest.mark.parametrize("series_name,series", get_dict_of_test_series().items())
 def test_format_column(series_name, series):
     values = list(_format_column(series))