codecov-io: # [Codecov](https://codecov.io/gh/openml/openml-python/pull/823?src=pr&el=h1) Report
> Merging [#823](https://codecov.io/gh/openml/openml-python/pull/823?src=pr&el=desc) into [develop](https://codecov.io/gh/openml/openml-python/commit/4853d7cfa279e5fb348cc96471c4cf61fdaf8b23?src=pr&el=desc) will **increase** coverage by `1.23%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/openml/openml-python/pull/823/graphs/tree.svg?width=650&token=IlImE4jvlP&height=150&src=pr)](https://codecov.io/gh/openml/openml-python/pull/823?src=pr&el=tree)

```diff
@@             Coverage Diff             @@
##           develop     #823      +/-   ##
===========================================
+ Coverage    88.05%   89.28%   +1.23%     
===========================================
  Files           36       36              
  Lines         4243     4768     +525     
===========================================
+ Hits          3736     4257     +521     
- Misses         507      511       +4
```


| [Impacted Files](https://codecov.io/gh/openml/openml-python/pull/823?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [openml/datasets/dataset.py](https://codecov.io/gh/openml/openml-python/pull/823/diff?src=pr&el=tree#diff-b3Blbm1sL2RhdGFzZXRzL2RhdGFzZXQucHk=) | `90.15% <100%> (+2.68%)` | :arrow_up: |
| [openml/flows/flow.py](https://codecov.io/gh/openml/openml-python/pull/823/diff?src=pr&el=tree#diff-b3Blbm1sL2Zsb3dzL2Zsb3cucHk=) | `94.24% <0%> (+0.37%)` | :arrow_up: |
| [openml/extensions/sklearn/extension.py](https://codecov.io/gh/openml/openml-python/pull/823/diff?src=pr&el=tree#diff-b3Blbm1sL2V4dGVuc2lvbnMvc2tsZWFybi9leHRlbnNpb24ucHk=) | `94.01% <0%> (+2.73%)` | :arrow_up: |
| [openml/exceptions.py](https://codecov.io/gh/openml/openml-python/pull/823/diff?src=pr&el=tree#diff-b3Blbm1sL2V4Y2VwdGlvbnMucHk=) | `97.67% <0%> (+4.12%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/openml/openml-python/pull/823?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/openml/openml-python/pull/823?src=pr&el=footer). Last update [4853d7c...b06d348](https://codecov.io/gh/openml/openml-python/pull/823?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

diff --git a/openml/datasets/dataset.py b/openml/datasets/dataset.py
index fb760583..fde45cc5 100644
--- a/openml/datasets/dataset.py
+++ b/openml/datasets/dataset.py
@@ -109,17 +109,18 @@ class OpenMLDataset(object):
                  paper_url=None, update_comment=None,
                  md5_checksum=None, data_file=None, features=None,
                  qualities=None, dataset=None):
-        if description and not re.match("^[\x00-\x7F]*$", description):
-            # not basiclatin (XSD complains)
-            raise ValueError("Invalid symbols in description: {}".format(
-                description))
-        if citation and not re.match("^[\x00-\x7F]*$", citation):
-            # not basiclatin (XSD complains)
-            raise ValueError("Invalid symbols in citation: {}".format(
-                citation))
-        if not re.match("^[a-zA-Z0-9_\\-\\.\\(\\),]+$", name):
-            # regex given by server in error message
-            raise ValueError("Invalid symbols in name: {}".format(name))
+        if dataset_id is None:
+            if description and not re.match("^[\x00-\x7F]*$", description):
+                # not basiclatin (XSD complains)
+                raise ValueError("Invalid symbols in description: {}".format(
+                    description))
+            if citation and not re.match("^[\x00-\x7F]*$", citation):
+                # not basiclatin (XSD complains)
+                raise ValueError("Invalid symbols in citation: {}".format(
+                    citation))
+            if not re.match("^[a-zA-Z0-9_\\-\\.\\(\\),]+$", name):
+                # regex given by server in error message
+                raise ValueError("Invalid symbols in name: {}".format(name))
         # TODO add function to check if the name is casual_string128
         # Attributes received by querying the RESTful API
         self.dataset_id = int(dataset_id) if dataset_id is not None else None
@@ -257,6 +258,7 @@ class OpenMLDataset(object):
             when converted to lower case.
 
 
+
         Returns
         -------
         dict
@@ -331,13 +333,15 @@ class OpenMLDataset(object):
         attribute_names = []
         categories_names = {}
         categorical = []
-        for name, type_ in data['attributes']:
+        for i, (name, type_) in enumerate(data['attributes']):
             # if the feature is nominal and the a sparse matrix is
             # requested, the categories need to be numeric
             if (isinstance(type_, list)
                     and self.format.lower() == 'sparse_arff'):
                 try:
-                    np.array(type_, dtype=np.float32)
+                    # checks if the strings which should be the class labels
+                    # can be encoded into integers
+                    pd.factorize(type_)[0]
                 except ValueError:
                     raise ValueError(
                         "Categorical data needs to be numeric when "

Cannot load sparse datasets with categorical variables any more
Can be reproduced with:

```
import openml

openml.datasets.get_dataset(395)
```
diff --git a/tests/test_datasets/test_dataset.py b/tests/test_datasets/test_dataset.py
index 5388c4bb..9d107637 100644
--- a/tests/test_datasets/test_dataset.py
+++ b/tests/test_datasets/test_dataset.py
@@ -9,6 +9,7 @@ from scipy import sparse
 import openml
 from openml.testing import TestBase
 from openml.exceptions import PyOpenMLError
+from openml.datasets import OpenMLDataset, OpenMLDataFeature
 
 
 class OpenMLDatasetTest(TestBase):
@@ -341,6 +342,16 @@ class OpenMLDatasetTestSparse(TestBase):
         self.assertListEqual(categorical, [False] * 19998)
         self.assertEqual(y.shape, (600, ))
 
+    def test_get_sparse_categorical_data_id_395(self):
+        dataset = openml.datasets.get_dataset(395, download_data=True)
+        feature = dataset.features[3758]
+        self.assertTrue(isinstance(dataset, OpenMLDataset))
+        self.assertTrue(isinstance(feature, OpenMLDataFeature))
+        self.assertEqual(dataset.name, 're1.wc')
+        self.assertEqual(feature.name, 'CLASS_LABEL')
+        self.assertEqual(feature.data_type, 'nominal')
+        self.assertEqual(len(feature.nominal_values), 25)
+
 
 class OpenMLDatasetQualityTest(TestBase):
     def test__check_qualities(self):

pip install -e .[test]
parse_log_pytest
pytest
pytest pytest-cov pytest-xdist pytest-mock pytest-asyncio
apt-get update apt-get install -y gcc
3.7
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs @ file:///croot/attrs_1668696182826/work
beautifulsoup4==4.13.3
bleach==6.0.0
certifi @ file:///croot/certifi_1671487769961/work/certifi
charset-normalizer==3.4.1
coverage==7.2.7
cycler==0.11.0
debtcollector==2.5.0
defusedxml==0.7.1
entrypoints==0.4
execnet==2.0.2
fasteners==0.19
fastjsonschema==2.21.1
flaky==3.8.1
flit_core @ file:///opt/conda/conda-bld/flit-core_1644941570762/work/source/flit_core
fonttools==4.38.0
idna==3.10
importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1648562407465/work
importlib-resources==5.12.0
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
iso8601==2.1.0
Jinja2==3.1.6
joblib==1.3.2
jsonschema==4.17.3
jupyter_client==7.4.9
jupyter_core==4.12.0
jupyterlab-pygments==0.2.2
kiwisolver==1.4.5
liac-arff==2.5.0
MarkupSafe==2.1.5
matplotlib==3.5.3
mistune==3.0.2
nbclient==0.7.4
nbconvert==7.6.0
nbformat==5.8.0
nest-asyncio==1.6.0
netaddr==1.3.0
netifaces==0.11.0
numpy==1.21.6
-e git+https://github.com/openml/openml-python.git@4853d7cfa279e5fb348cc96471c4cf61fdaf8b23#egg=openml
oslo.concurrency==4.5.1
oslo.config==8.8.1
oslo.i18n==5.1.0
oslo.utils==4.13.0
packaging @ file:///croot/packaging_1671697413597/work
pandas==1.3.5
pandocfilters==1.5.1
pbr==6.1.1
Pillow==9.5.0
pkgutil_resolve_name==1.3.10
pluggy @ file:///tmp/build/80754af9/pluggy_1648042572264/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
Pygments==2.17.2
pyparsing==3.1.4
pyrsistent==0.19.3
pytest==7.1.2
pytest-asyncio==0.21.2
pytest-cov==4.1.0
pytest-mock==3.11.1
pytest-timeout==2.3.1
pytest-xdist==3.5.0
python-dateutil==2.9.0.post0
pytz==2025.2
PyYAML==6.0.1
pyzmq==26.2.1
requests==2.31.0
rfc3986==2.0.0
scikit-learn==1.0.2
scipy==1.7.3
six==1.17.0
soupsieve==2.4.1
stevedore==3.5.2
threadpoolctl==3.1.0
tinycss2==1.2.1
tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work
tornado==6.2
traitlets==5.9.0
typing_extensions @ file:///croot/typing_extensions_1669924550328/work
urllib3==2.0.7
webencodings==0.5.1
wrapt==1.16.0
xmltodict==0.14.2
zipp @ file:///croot/zipp_1672387121353/work

name: openml-python
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=22.1.0=py37h06a4308_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - flit-core=3.6.0=pyhd3eb1b0_0
  - importlib-metadata=4.11.3=py37h06a4308_0
  - importlib_metadata=4.11.3=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=22.0=py37h06a4308_0
  - pip=22.3.1=py37h06a4308_0
  - pluggy=1.0.0=py37h06a4308_1
  - py=1.11.0=pyhd3eb1b0_0
  - pytest=7.1.2=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tomli=2.0.1=py37h06a4308_0
  - typing_extensions=4.4.0=py37h06a4308_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.11.0=py37h06a4308_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - beautifulsoup4==4.13.3
      - bleach==6.0.0
      - charset-normalizer==3.4.1
      - coverage==7.2.7
      - cycler==0.11.0
      - debtcollector==2.5.0
      - defusedxml==0.7.1
      - entrypoints==0.4
      - execnet==2.0.2
      - fasteners==0.19
      - fastjsonschema==2.21.1
      - flaky==3.8.1
      - fonttools==4.38.0
      - idna==3.10
      - importlib-resources==5.12.0
      - iso8601==2.1.0
      - jinja2==3.1.6
      - joblib==1.3.2
      - jsonschema==4.17.3
      - jupyter-client==7.4.9
      - jupyter-core==4.12.0
      - jupyterlab-pygments==0.2.2
      - kiwisolver==1.4.5
      - liac-arff==2.5.0
      - markupsafe==2.1.5
      - matplotlib==3.5.3
      - mistune==3.0.2
      - nbclient==0.7.4
      - nbconvert==7.6.0
      - nbformat==5.8.0
      - nest-asyncio==1.6.0
      - netaddr==1.3.0
      - netifaces==0.11.0
      - numpy==1.21.6
      - oslo-concurrency==4.5.1
      - oslo-config==8.8.1
      - oslo-i18n==5.1.0
      - oslo-utils==4.13.0
      - pandas==1.3.5
      - pandocfilters==1.5.1
      - pbr==6.1.1
      - pillow==9.5.0
      - pkgutil-resolve-name==1.3.10
      - pygments==2.17.2
      - pyparsing==3.1.4
      - pyrsistent==0.19.3
      - pytest-asyncio==0.21.2
      - pytest-cov==4.1.0
      - pytest-mock==3.11.1
      - pytest-timeout==2.3.1
      - pytest-xdist==3.5.0
      - python-dateutil==2.9.0.post0
      - pytz==2025.2
      - pyyaml==6.0.1
      - pyzmq==26.2.1
      - requests==2.31.0
      - rfc3986==2.0.0
      - scikit-learn==1.0.2
      - scipy==1.7.3
      - six==1.17.0
      - soupsieve==2.4.1
      - stevedore==3.5.2
      - threadpoolctl==3.1.0
      - tinycss2==1.2.1
      - tornado==6.2
      - traitlets==5.9.0
      - urllib3==2.0.7
      - webencodings==0.5.1
      - wrapt==1.16.0
      - xmltodict==0.14.2
prefix: /opt/conda/envs/openml-python

tests/test_datasets/test_dataset.py::OpenMLDatasetTestSparse::test_get_sparse_categorical_data_id_395
tests/test_datasets/test_dataset.py::OpenMLDatasetTestOnTestServer::test_tagging tests/test_datasets/test_dataset.py::OpenMLDatasetTestSparse::test_get_sparse_dataframe
tests/test_datasets/test_dataset.py::OpenMLDatasetTest::test_dataset_format_constructor tests/test_datasets/test_dataset.py::OpenMLDatasetTest::test_get_data_array tests/test_datasets/test_dataset.py::OpenMLDatasetTest::test_get_data_boolean_pandas tests/test_datasets/test_dataset.py::OpenMLDatasetTest::test_get_data_corrupt_pickle tests/test_datasets/test_dataset.py::OpenMLDatasetTest::test_get_data_no_str_data_for_nparrays tests/test_datasets/test_dataset.py::OpenMLDatasetTest::test_get_data_pandas tests/test_datasets/test_dataset.py::OpenMLDatasetTest::test_get_data_rowid_and_ignore_and_target tests/test_datasets/test_dataset.py::OpenMLDatasetTest::test_get_data_with_ignore_attributes tests/test_datasets/test_dataset.py::OpenMLDatasetTest::test_get_data_with_nonexisting_class tests/test_datasets/test_dataset.py::OpenMLDatasetTest::test_get_data_with_rowid tests/test_datasets/test_dataset.py::OpenMLDatasetTest::test_get_data_with_target_array tests/test_datasets/test_dataset.py::OpenMLDatasetTest::test_get_data_with_target_pandas tests/test_datasets/test_dataset.py::OpenMLDatasetTest::test_init_string_validation tests/test_datasets/test_dataset.py::OpenMLDatasetTest::test_repr tests/test_datasets/test_dataset.py::OpenMLDatasetTestSparse::test_get_sparse_dataset tests/test_datasets/test_dataset.py::OpenMLDatasetTestSparse::test_get_sparse_dataset_rowid_and_ignore_and_target tests/test_datasets/test_dataset.py::OpenMLDatasetTestSparse::test_get_sparse_dataset_with_ignore_attributes tests/test_datasets/test_dataset.py::OpenMLDatasetTestSparse::test_get_sparse_dataset_with_rowid tests/test_datasets/test_dataset.py::OpenMLDatasetTestSparse::test_get_sparse_dataset_with_target tests/test_datasets/test_dataset.py::OpenMLDatasetQualityTest::test__check_qualities
openml/datasets/dataset.py
openml/datasets/dataset.py