Skip to content

Conversation

@filabrazilska
Copy link
Contributor

The code would throw an error because of the sum being left in. When replaced with result["sum"].mean().compute() it computes the mean correctly:

>>> import dask.datasets
>>> dask.config.set({"dataframe.convert-string": False})
<dask.config.set object at 0x7feccbf70a10>
>>> from dask_sql import Context
>>> df = dask.datasets.timeseries()
>>> c = Context()
>>> c.create_table("timeseries", df)
>>> result = c.sql("""
... SELECT name, SUM(x) as "sum" FROM timeseries GROUP BY name
... """)
>>> result["sum"].mean().compute()
7.956598887824248

Also eager string converting needs to be turned off in order to silence the following error:

>>> result = c.sql("""
... SELECT name, SUM(x) as "sum" FROM timeseries GROUP BY name
... """)
Traceback (most recent call last):
  File "/home/fila/miniconda3/envs/dask-sql/lib/python3.11/site-packages/dask_sql/mappings.py", line 118, in python_to_sql_type
    return DaskTypeMap(_PYTHON_TO_SQL[python_type])
                       ~~~~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: string[pyarrow]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/fila/miniconda3/envs/dask-sql/lib/python3.11/site-packages/dask_sql/context.py", line 517, in sql
    rel, _ = self._get_ral(sql)
             ^^^^^^^^^^^^^^^^^^
  File "/home/fila/miniconda3/envs/dask-sql/lib/python3.11/site-packages/dask_sql/context.py", line 826, in _get_ral
    schemas = self._prepare_schemas()
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fila/miniconda3/envs/dask-sql/lib/python3.11/site-packages/dask_sql/context.py", line 773, in _prepare_schemas
    column_type_mapping = list(
                          ^^^^^
  File "/home/fila/miniconda3/envs/dask-sql/lib/python3.11/site-packages/dask_sql/mappings.py", line 120, in python_to_sql_type
    raise NotImplementedError(
NotImplementedError: The python type string is not implemented (yet)

The code would throw an error because of the `sum` being left in.
When replaced with `result["sum"].mean().compute()` it computes
the mean correctly:

```python
>>> import dask.datasets
>>> dask.config.set({"dataframe.convert-string": False})
<dask.config.set object at 0x7feccbf70a10>
>>> from dask_sql import Context
>>> df = dask.datasets.timeseries()
>>> c = Context()
>>> c.create_table("timeseries", df)
>>> result = c.sql("""
... SELECT name, SUM(x) as "sum" FROM timeseries GROUP BY name
... """)
>>> result["sum"].mean().compute()
7.956598887824248
```

Also eager string converting needs to be turned off in order to silence
the following error:
```python
>>> result = c.sql("""
... SELECT name, SUM(x) as "sum" FROM timeseries GROUP BY name
... """)
Traceback (most recent call last):
  File "/home/fila/miniconda3/envs/dask-sql/lib/python3.11/site-packages/dask_sql/mappings.py", line 118, in python_to_sql_type
    return DaskTypeMap(_PYTHON_TO_SQL[python_type])
                       ~~~~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: string[pyarrow]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/fila/miniconda3/envs/dask-sql/lib/python3.11/site-packages/dask_sql/context.py", line 517, in sql
    rel, _ = self._get_ral(sql)
             ^^^^^^^^^^^^^^^^^^
  File "/home/fila/miniconda3/envs/dask-sql/lib/python3.11/site-packages/dask_sql/context.py", line 826, in _get_ral
    schemas = self._prepare_schemas()
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fila/miniconda3/envs/dask-sql/lib/python3.11/site-packages/dask_sql/context.py", line 773, in _prepare_schemas
    column_type_mapping = list(
                          ^^^^^
  File "/home/fila/miniconda3/envs/dask-sql/lib/python3.11/site-packages/dask_sql/mappings.py", line 120, in python_to_sql_type
    raise NotImplementedError(
NotImplementedError: The python type string is not implemented (yet)
```
@GPUtester
Copy link

Can one of the admins verify this patch?

Admins can comment ok to test to allow this one PR to run or add to allowlist to allow all future PRs from the same author to run.

@charlesbluca
Copy link
Collaborator

ok to test

Copy link
Collaborator

@charlesbluca charlesbluca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @filabrazilska! Also noting that the issues with eager string conversion should at least be less visible now with #1260 in, though I'm hopeful we can implement full support for PyArrow strings in the near future

@charlesbluca charlesbluca merged commit b473fd6 into dask-contrib:main Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants