Repository navigation
Remove and rewrite unnecessary Polars, Arrow, and S3FS cursor tests #1252
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ff8012b
Remove and rewrite redundant Polars cursor tests
laughingman7743 9529eb2
Remove and rewrite redundant Arrow cursor tests
laughingman7743 d894953
Remove and rewrite redundant S3FS cursor tests
laughingman7743 5a8b810
Check that storage options reach chunked CSV reads and that fetches stop
laughingman7743 6b8f9ea
Read the local Polars results through GetQueryResults and as_polars()
laughingman7743 738069e
Check the read options and conversions that the removed tests protected
laughingman7743 558f368
Test the cleanup and routing that the follow-up review found untested
laughingman7743 5b64fc7
Read the S3FS test metadata through GetQueryResults
laughingman7743 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,6 @@ | |
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pandas as pd | ||
| import polars as pl | ||
| import pyarrow as pa | ||
| import pytest | ||
|
|
||
|
|
@@ -566,186 +565,11 @@ def test_complex_unload_as_arrow(self, arrow_cursor): | |
| ) | ||
| ] | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "arrow_cursor", | ||
| [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], | ||
| indirect=["arrow_cursor"], | ||
| ) | ||
| def test_as_polars(self, arrow_cursor): | ||
| df = arrow_cursor.execute("SELECT * FROM one_row").as_polars() | ||
| assert df.height == 1 | ||
| assert df.width == 1 | ||
| assert df.to_dicts() == [{"number_of_rows": 1}] | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "arrow_cursor", | ||
| [{"cursor_kwargs": {"unload": False}}, {"cursor_kwargs": {"unload": True}}], | ||
| indirect=["arrow_cursor"], | ||
| ) | ||
| def test_many_as_polars(self, arrow_cursor): | ||
| df = arrow_cursor.execute("SELECT * FROM many_rows").as_polars() | ||
| assert df.height == 10000 | ||
| assert df.width == 1 | ||
| assert df.to_dicts() == [{"a": i} for i in range(10000)] | ||
|
|
||
| def test_complex_as_polars(self, arrow_cursor): | ||
| df = arrow_cursor.execute( | ||
| """ | ||
| SELECT | ||
| col_boolean | ||
| ,col_tinyint | ||
| ,col_smallint | ||
| ,col_int | ||
| ,col_bigint | ||
| ,col_float | ||
| ,col_double | ||
| ,col_string | ||
| ,col_varchar | ||
| ,col_timestamp | ||
| ,CAST(col_timestamp AS time) AS col_time | ||
| ,col_date | ||
| ,col_binary | ||
| ,col_array | ||
| ,CAST(col_array AS json) AS col_array_json | ||
| ,col_map | ||
| ,CAST(col_map AS json) AS col_map_json | ||
| ,col_struct | ||
| ,col_decimal | ||
| FROM one_row_complex | ||
| """ | ||
| ).as_polars() | ||
| assert df.height == 1 | ||
| assert df.width == 19 | ||
| dtypes = tuple(df.dtypes) | ||
| assert dtypes == ( | ||
| pl.Boolean, | ||
| pl.Int8, | ||
| pl.Int16, | ||
| pl.Int32, | ||
| pl.Int64, | ||
| pl.Float32, | ||
| pl.Float64, | ||
| pl.String, | ||
| pl.String, | ||
| pl.Datetime("us"), | ||
| pl.String, | ||
| pl.Date, | ||
| pl.String, | ||
| pl.String, | ||
| pl.String, | ||
| pl.String, | ||
| pl.String, | ||
| pl.String, | ||
| pl.String, | ||
| ) | ||
| rows = df.to_dicts() | ||
| assert rows == [ | ||
| { | ||
| "col_boolean": True, | ||
| "col_tinyint": 127, | ||
| "col_smallint": 32767, | ||
| "col_int": 2147483647, | ||
| "col_bigint": 9223372036854775807, | ||
| "col_float": 0.5, | ||
| "col_double": 0.25, | ||
| "col_string": "a string", | ||
| "col_varchar": "varchar", | ||
| "col_timestamp": datetime(2017, 1, 1, 0, 0, 0), | ||
| "col_time": "00:00:00.000", | ||
| "col_date": datetime(2017, 1, 2).date(), | ||
| "col_binary": "31 32 33", | ||
| "col_array": "[1, 2]", | ||
| "col_array_json": "[1,2]", | ||
| "col_map": "{1=2, 3=4}", | ||
| "col_map_json": '{"1":2,"3":4}', | ||
| "col_struct": "{a=1, b=2}", | ||
| "col_decimal": "0.1", | ||
| } | ||
| ] | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "arrow_cursor", | ||
| [ | ||
| { | ||
| "cursor_kwargs": {"unload": True}, | ||
| }, | ||
| ], | ||
| indirect=["arrow_cursor"], | ||
| ) | ||
| def test_complex_unload_as_polars(self, arrow_cursor): | ||
| # NOT_SUPPORTED: Unsupported Hive type: time | ||
| # NOT_SUPPORTED: Unsupported Hive type: json | ||
| df = arrow_cursor.execute( | ||
| """ | ||
| SELECT | ||
| col_boolean | ||
| ,col_tinyint | ||
| ,col_smallint | ||
| ,col_int | ||
| ,col_bigint | ||
| ,col_float | ||
| ,col_double | ||
| ,col_string | ||
| ,col_varchar | ||
| ,col_timestamp | ||
| ,col_date | ||
| ,col_binary | ||
| ,col_array | ||
| ,col_map | ||
| ,col_struct | ||
| ,col_decimal | ||
| FROM one_row_complex | ||
| """ | ||
| "SELECT * FROM (VALUES (1, 'a'), (2, 'b')) AS t(k, s) ORDER BY k" | ||
| ).as_polars() | ||
| assert df.height == 1 | ||
| assert df.width == 16 | ||
| # Polars 2.0 converts an Arrow map to Map; Polars 1.x to a list of key-value structs. | ||
| if hasattr(pl, "Map"): | ||
| map_dtype = pl.Map(pl.Int32, pl.Int32) | ||
| map_value = {1: 2, 3: 4} | ||
| else: | ||
| map_dtype = pl.List(pl.Struct([pl.Field("key", pl.Int32), pl.Field("value", pl.Int32)])) | ||
| map_value = [{"key": 1, "value": 2}, {"key": 3, "value": 4}] | ||
| dtypes = tuple(df.dtypes) | ||
| assert dtypes == ( | ||
| pl.Boolean, | ||
| pl.Int8, | ||
| pl.Int16, | ||
| pl.Int32, | ||
| pl.Int64, | ||
| pl.Float32, | ||
| pl.Float64, | ||
| pl.String, | ||
| pl.String, | ||
| pl.Datetime("us"), | ||
| pl.Date, | ||
| pl.Binary, | ||
| pl.List(pl.Int32), | ||
| map_dtype, | ||
| pl.Struct([pl.Field("a", pl.Int32), pl.Field("b", pl.Int32)]), | ||
| pl.Decimal(precision=10, scale=1), | ||
| ) | ||
| rows = df.to_dicts() | ||
| assert rows == [ | ||
| { | ||
| "col_boolean": True, | ||
| "col_tinyint": 127, | ||
| "col_smallint": 32767, | ||
| "col_int": 2147483647, | ||
| "col_bigint": 9223372036854775807, | ||
| "col_float": 0.5, | ||
| "col_double": 0.25, | ||
| "col_string": "a string", | ||
| "col_varchar": "varchar", | ||
| "col_timestamp": datetime(2017, 1, 1, 0, 0, 0), | ||
| "col_date": datetime(2017, 1, 2).date(), | ||
| "col_binary": b"123", | ||
| "col_array": [1, 2], | ||
| "col_map": map_value, | ||
| "col_struct": {"a": 1, "b": 2}, | ||
| "col_decimal": Decimal("0.1"), | ||
| } | ||
| ] | ||
| assert df.to_dicts() == [{"k": 1, "s": "a"}, {"k": 2, "s": "b"}] | ||
|
|
||
| def test_cancel(self, arrow_cursor): | ||
| def cancel(c): | ||
|
|
@@ -980,49 +804,6 @@ def test_callback(query_id: str): | |
| assert callback_results[0] == arrow_cursor.query_id | ||
| assert arrow_cursor.query_id is not None | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "arrow_cursor", | ||
| [ | ||
| { | ||
| "cursor_kwargs": { | ||
| "connect_timeout": 10, | ||
| "request_timeout": 30, | ||
| } | ||
| } | ||
| ], | ||
| indirect=["arrow_cursor"], | ||
| ) | ||
| def test_timeout_parameters(self, arrow_cursor): | ||
| """Test that timeout parameters are correctly passed to ArrowCursor and result set.""" | ||
| # Verify timeout parameters are set on cursor | ||
| assert arrow_cursor._connect_timeout == 10 | ||
| assert arrow_cursor._request_timeout == 30 | ||
|
|
||
| # Execute a simple query to create a result set | ||
| arrow_cursor.execute("SELECT 1") | ||
|
|
||
| # Verify timeout parameters are passed to result set | ||
| assert arrow_cursor.result_set._connect_timeout == 10 | ||
| assert arrow_cursor.result_set._request_timeout == 30 | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "arrow_cursor", | ||
| [{"cursor_kwargs": {"connect_timeout": 5.5, "request_timeout": 15.5}}], | ||
| indirect=["arrow_cursor"], | ||
| ) | ||
| def test_timeout_parameters_float(self, arrow_cursor): | ||
| """Test that timeout parameters accept float values.""" | ||
| # Verify float timeout parameters are set on cursor | ||
| assert arrow_cursor._connect_timeout == 5.5 | ||
| assert arrow_cursor._request_timeout == 15.5 | ||
|
|
||
| # Execute a simple query to create a result set | ||
| arrow_cursor.execute("SELECT 1") | ||
|
|
||
| # Verify float timeout parameters are passed to result set | ||
| assert arrow_cursor.result_set._connect_timeout == 5.5 | ||
| assert arrow_cursor.result_set._request_timeout == 15.5 | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "arrow_cursor", | ||
| [ | ||
|
|
@@ -1189,10 +970,13 @@ def test_managed_results_match_result_file(self): | |
| indirect=["arrow_cursor"], | ||
| ) | ||
| def test_duplicate_column_names(self, arrow_cursor): | ||
| """Columns with the same name keep their own types, as do their timestamps and NULLs.""" | ||
| arrow_cursor.execute( | ||
| "SELECT 1 AS x, 2 AS x, CAST('01:02:03' AS TIME) AS x, 'a' AS y, " | ||
| "json_parse('[1]') AS j, 'b' AS j, CAST('12:34:56' AS TIME) AS t, " | ||
| "CAST('01:02:03' AS TIME) AS t" | ||
| "CAST('01:02:03' AS TIME) AS t, " | ||
| "CAST('2020-01-02 03:04:05.123456789' AS TIMESTAMP(9)) AS x, " | ||
| "CAST(NULL AS TIMESTAMP) AS x" | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Round 1 FINDINGS, repaired in 5a8b810: the merge of |
||
| ) | ||
| assert arrow_cursor.fetchall() == [ | ||
| ( | ||
|
|
@@ -1204,9 +988,22 @@ def test_duplicate_column_names(self, arrow_cursor): | |
| "b", | ||
| datetime(2017, 1, 1, 12, 34, 56).time(), | ||
| datetime(2017, 1, 1, 1, 2, 3).time(), | ||
| datetime(2020, 1, 2, 3, 4, 5, 123456), | ||
| None, | ||
| ) | ||
| ] | ||
| assert arrow_cursor.as_arrow().column_names == ["x", "x", "x", "y", "j", "j", "t", "t"] | ||
| assert arrow_cursor.as_arrow().column_names == [ | ||
| "x", | ||
| "x", | ||
| "x", | ||
| "y", | ||
| "j", | ||
| "j", | ||
| "t", | ||
| "t", | ||
| "x", | ||
| "x", | ||
| ] | ||
|
|
||
| def test_duplicate_column_names_with_newline(self, arrow_cursor): | ||
| """Columns with the same name keep their own types, with a newline in the name.""" | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Independent review (relayed): Codex CLI 0.163.0, model gpt-6-astra, ChatGPT login,
codex exec -s read-only, session 01a149cf-467f-78a3-9798-57123cbadabe. Static review of713d57bde5248f9a77b763b44eb4c6945ceb4361..6b8f9ea66f66a752bba7cb832ab6e9b5a357a6d4in a clean detached snapshot, with the diff, thedocs/testing.md"Choose what to test" section, and no PR text or author findings; no edits, builds, tests, network, or GitHub access. Covered: all 11 changed files, the removed tests at the base, the cursor and result-set code, remaining tests undertests/pyathena/, the three changed helpers, live-query expectations, IDs, marks, fixture scopes, and cleanup. Result: FINDINGS (7).Finding 1 (P2): with
test_many_as_polarsremoved, only single-row results exerciseAthenaArrowResultSet.as_polars();pl.from_arrow(self._table.slice(0, 1))atpyathena/arrow/result_set.py:448would pass. The removed complex tests were the only multi-column inputs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repaired in 738069e:
test_as_polarsreadsVALUES (1, 'a'), (2, 'b')(two rows, two columns, one query) and comparesto_dicts(). A truncatingas_polars()now fails it. Not yet run against Athena.