Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create FeatureSets from features like specified in the docstring #2246

Closed
Zethson opened this issue Dec 3, 2024 · 1 comment
Closed
Assignees
Labels

Comments

@Zethson
Copy link
Member

Zethson commented Dec 3, 2024

Add a description

We have examples such as the below (slightly modified) in the docstring of ln.Featureset.from_values. However, they currently do not work because of https://github.com/laminlabs/lamin-utils/blob/main/lamin_utils/_inspect.py#L176 which identifies all passed Feature as unknown. It should check the Feature.dtype instead.

Code:

features = [ln.Feature(name=feat, dtype="str") for feat in ["feat1", "feat2"]]
ln.save(features)
feature_set = ln.FeatureSet.from_values(features)

Error:

{
	"name": "TypeError",
	"message": "Type mismatch: identifiers are 'unknown' but field_values are 'str/categorical'.",
	"stack": "---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 3
      1 features = [ln.Feature(name=feat, dtype=\"str\") for feat in [\"feat3\", \"feat4\"]]
      2 ln.save(features)
----> 3 feature_set = ln.FeatureSet.from_values(features)

File ~/PycharmProjects/lamindb/lamindb/_feature_set.py:136, in from_values(cls, values, field, type, name, mute, organism, source, raise_validation_error)
    134     type = NUMBER_TYPE
    135     logger.debug(\"setting feature set to 'number'\")
--> 136 validated = registry.validate(values, field=field, mute=mute, organism=organism)
    137 values_array = np.array(values)
    138 validated_values = values_array[validated]

File ~/PycharmProjects/lamindb/lamindb/_can_curate.py:87, in validate(cls, values, field, mute, organism, source)
     75 @classmethod  # type: ignore
     76 @doc_args(CanCurate.validate.__doc__)
     77 def validate(
   (...)
     84     source: Record | None = None,
     85 ) -> np.ndarray:
     86     \"\"\"{}\"\"\"  # noqa: D415
---> 87     return _validate(
     88         cls=cls, values=values, field=field, mute=mute, organism=organism, source=source
     89     )

File ~/PycharmProjects/lamindb/lamindb/_can_curate.py:259, in _validate(cls, values, field, mute, using_key, organism, source)
    256         logger.warning(msg)
    257     return np.array([False] * len(values))
--> 259 result = validate(
    260     identifiers=values,
    261     field_values=field_values,
    262     case_sensitive=True,
    263     mute=mute,
    264     field=field,
    265 )
    266 if return_str and len(result) == 1:
    267     return result[0]

File ~/PycharmProjects/lamin-utils/lamin_utils/_inspect.py:134, in validate(identifiers, field_values, case_sensitive, mute, field, **kwargs)
    131     mute = not kwargs.get(\"logging\")
    132 import pandas as pd
--> 134 _check_type_compatibility(identifiers, field_values)
    136 identifiers = list(identifiers)
    137 identifiers_idx = pd.Index(identifiers)

File ~/PycharmProjects/lamin-utils/lamin_utils/_inspect.py:198, in _check_type_compatibility(identifiers, field_values)
    192 id_type, value_type = (
    193     _get_type_category(id_sample),
    194     _get_type_category(value_sample),
    195 )
    197 if id_type != value_type:
--> 198     raise TypeError(
    199         f\"Type mismatch: identifiers are '{id_type}' but field_values are '{value_type}'.\"
    200     )

TypeError: Type mismatch: identifiers are 'unknown' but field_values are 'str/categorical'."
}

Creating the issue here but it's across lnschema-core (fix examples) & lamin-utils

@Zethson Zethson self-assigned this Dec 3, 2024
@Zethson Zethson changed the title Unable to create FeatureSets from features like in the docstring Unable to create FeatureSets from features like specified in the docstring Dec 3, 2024
@Zethson
Copy link
Member Author

Zethson commented Dec 3, 2024

Nevermind, think it does work.

@Zethson Zethson closed this as completed Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant