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

bug: ibis can't handle response from mssql when statement is CAST('2024-01-01 00:00:00' AS DATETIMEOFFSET) #10025

Closed
1 task done
grieve54706 opened this issue Sep 5, 2024 · 3 comments · Fixed by #10028
Closed
1 task done
Labels
bug Incorrect behavior inside of ibis mssql The Microsoft SQL Server backend

Comments

@grieve54706
Copy link
Contributor

What happened?

Ibis will raise an error when I use a statement with CAST AS DATETIMEOFFSET for mssql.

import ibis

ibis.mssql.connect(...).sql("SELECT CAST('2024-01-01 00:00:00' AS DATETIMEOFFSET)").to_pandas()

What version of ibis are you using?

9.2.0

What backend(s) are you using, if any?

mssql

Relevant log output

return self.connection.sql(sql).limit(limit).to_pandas()
../.venv/lib/python3.11/site-packages/ibis/backends/sql/__init__.py:203: in sql
    schema = self._get_schema_using_query(query)
../.venv/lib/python3.11/site-packages/ibis/backends/mssql/__init__.py:247: in _get_schema_using_query
    return sch.Schema(schema)
../.venv/lib/python3.11/site-packages/ibis/common/bases.py:72: in __call__
    return cls.__create__(*args, **kwargs)
../.venv/lib/python3.11/site-packages/ibis/common/grounds.py:119: in __create__
    kwargs = cls.__signature__.validate(cls, args, kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Signature (fields: FrozenOrderedDict[str, DataType])>
func = <class 'ibis.expr.schema.Schema'>
args = ({None: Timestamp(timezone='UTC', scale=7, nullable=True)},), kwargs = {}

    def validate(self, func, args, kwargs):
        """Validate the arguments against the signature.
    
        Parameters
        ----------
        func : Callable
            Callable to validate the arguments for.
        args : tuple
            Positional arguments.
        kwargs : dict
            Keyword arguments.
    
        Returns
        -------
        validated : dict
            Dictionary of validated arguments.
    
        """
        try:
            bound = self.bind(*args, **kwargs)
            bound.apply_defaults()
        except TypeError as err:
            raise SignatureValidationError(
                "{call} {cause}\n\nExpected signature: {sig}",
                sig=self,
                func=func,
                args=args,
                kwargs=kwargs,
            ) from err
    
        this, errors = {}, []
        for name, value in bound.arguments.items():
            param = self.parameters[name]
            pattern = param.annotation.pattern
    
            result = pattern.match(value, this)
            if result is NoMatch:
                errors.append((name, value, pattern))
            else:
                this[name] = result
    
        if errors:
>           raise SignatureValidationError(
                "{call} has failed due to the following errors:{errors}\n\nExpected signature: {sig}",
                sig=self,
                func=func,
                args=args,
                kwargs=kwargs,
                errors=errors,
            )
E           ibis.common.annotations.SignatureValidationError: Schema({None: Timestamp(timezone='UTC', scale=7, nullable=True)}) has failed due to the following errors:
E             `fields`: {None: Timestamp(timezone='UTC', scale=7, nullable=True)} is not matching GenericMappingOf(key=InstanceOf(type=<class 'str'>), value=CoercedTo(type=<class 'ibis.expr.datatypes.core.DataType'>, func=<bound method DataType.__coerce__ of <class 'ibis.expr.datatypes.core.DataType'>>), type=CoercedTo(type=<class 'ibis.common.collections.FrozenOrderedDict'>, func=<class 'ibis.common.collections.FrozenOrderedDict'>))
E           
E           Expected signature: Schema(fields: FrozenOrderedDict[str, DataType])

../.venv/lib/python3.11/site-packages/ibis/common/annotations.py:497: SignatureValidationError

Code of Conduct

  • I agree to follow this project's Code of Conduct
@grieve54706 grieve54706 added the bug Incorrect behavior inside of ibis label Sep 5, 2024
@grieve54706
Copy link
Contributor Author

If the statement is SELECT CAST('2024-01-01 00:00:00 -06:00' AS DATETIMEOFFSET) AS col_1 with a column name, it will be fine.

@cpcloud
Copy link
Member

cpcloud commented Sep 5, 2024

Glad you were able to find a workaround, but this still seems like a bug.

@grieve54706
Copy link
Contributor Author

Hi @cpcloud,

I appreciate you taking the time to fix this issue, even though I've closed the ticket. You are very kind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior inside of ibis mssql The Microsoft SQL Server backend
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants