sqlframe 3.33.1__py3-none-any.whl → 3.35.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sqlframe/_version.py CHANGED
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '3.33.1'
21
- __version_tuple__ = version_tuple = (3, 33, 1)
20
+ __version__ = version = '3.35.0'
21
+ __version_tuple__ = version_tuple = (3, 35, 0)
sqlframe/base/column.py CHANGED
@@ -128,6 +128,39 @@ class Column:
128
128
  "Tried to call a column which is unexpected. Did you mean to call a method on a DataFrame? If so, make sure the method is typed correctly and is supported. If not, please open an issue requesting support: https://github.com/eakmanrq/sqlframe/issues"
129
129
  )
130
130
 
131
+ def __getitem__(self, key: t.Any) -> Column:
132
+ """
133
+ An expression that gets an item at position ``ordinal`` out of a list,
134
+ or gets an item by key out of a dict.
135
+
136
+ .. versionadded:: 1.3.0
137
+
138
+ .. versionchanged:: 3.4.0
139
+ Supports Spark Connect.
140
+
141
+ Parameters
142
+ ----------
143
+ k
144
+ a literal value, or a slice object without step.
145
+
146
+ Returns
147
+ -------
148
+ :class:`Column`
149
+ Column representing the item got by key out of a dict, or substrings sliced by
150
+ the given slice object.
151
+
152
+ Examples
153
+ --------
154
+ >>> df = spark.createDataFrame([('abcedfg', {"key": "value"})], ["l", "d"])
155
+ >>> df.select(df.l[slice(1, 3)], df.d['key']).show()
156
+ +---------------+------+
157
+ |substr(l, 1, 3)|d[key]|
158
+ +---------------+------+
159
+ | abc| value|
160
+ +---------------+------+
161
+ """
162
+ return self.getItem(key)
163
+
131
164
  def __getattr__(self, name: str) -> Column:
132
165
  """
133
166
  Enables accessing nested fields using dot notation for struct types.
@@ -1524,6 +1524,52 @@ class BaseDataFrame(t.Generic[SESSION, WRITER, NA, STAT, GROUP_DATA]):
1524
1524
  raise ValueError("Tried to rename a column that doesn't exist")
1525
1525
  return self.select.__wrapped__(self, *results, skip_update_display_name_mapping=True) # type: ignore
1526
1526
 
1527
+ @operation(Operation.SELECT)
1528
+ def withColumnsRenamed(self, colsMap: t.Dict[str, str]) -> Self:
1529
+ """
1530
+ Returns a new :class:`DataFrame` by renaming multiple columns. If a non-existing column is
1531
+ provided, it will be silently ignored.
1532
+
1533
+ .. versionadded:: 3.5.0
1534
+
1535
+ Parameters
1536
+ ----------
1537
+ colsMap : dict
1538
+ a dict of column name and new column name.
1539
+
1540
+ Returns
1541
+ -------
1542
+ :class:`DataFrame`
1543
+ DataFrame with renamed columns.
1544
+
1545
+ Examples
1546
+ --------
1547
+ >>> df = spark.createDataFrame([(2, "Alice"), (5, "Bob")], schema=["age", "name"])
1548
+ >>> df.withColumnsRenamed({"age": "years", "name": "firstName"}).show()
1549
+ +-----+---------+
1550
+ |years|firstName|
1551
+ +-----+---------+
1552
+ | 2| Alice|
1553
+ | 5| Bob|
1554
+ +-----+---------+
1555
+ """
1556
+ expression = self.expression.copy()
1557
+ columns = self._get_outer_select_columns(expression)
1558
+ results = []
1559
+
1560
+ # Normalize the keys in colsMap
1561
+ normalized_cols_map = {self.session._normalize_string(k): v for k, v in colsMap.items()}
1562
+
1563
+ for column in columns:
1564
+ col_name = column.alias_or_name
1565
+ if col_name in normalized_cols_map:
1566
+ new_name = normalized_cols_map[col_name]
1567
+ column = column.alias(new_name)
1568
+ self._update_display_name_mapping([column], [new_name])
1569
+ results.append(column)
1570
+
1571
+ return self.select.__wrapped__(self, *results, skip_update_display_name_mapping=True) # type: ignore
1572
+
1527
1573
  @operation(Operation.SELECT)
1528
1574
  def withColumns(self, *colsMap: t.Dict[str, Column]) -> Self:
1529
1575
  """
@@ -51,7 +51,7 @@ class BigQuerySession(
51
51
  super().__init__(conn or connect())
52
52
  if self._client.default_query_job_config is None:
53
53
  self._client.default_query_job_config = bigquery.QueryJobConfig()
54
- self.default_dataset = default_dataset
54
+ self.default_dataset = default_dataset # type: ignore
55
55
 
56
56
  @property
57
57
  def _client(self) -> BigQueryClient:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sqlframe
3
- Version: 3.33.1
3
+ Version: 3.35.0
4
4
  Summary: Turning PySpark Into a Universal DataFrame API
5
5
  Home-page: https://github.com/eakmanrq/sqlframe
6
6
  Author: Ryan Eakman
@@ -17,7 +17,7 @@ Requires-Python: >=3.9
17
17
  Description-Content-Type: text/markdown
18
18
  License-File: LICENSE
19
19
  Requires-Dist: prettytable <4
20
- Requires-Dist: sqlglot <26.20,>=24.0.0
20
+ Requires-Dist: sqlglot <26.25,>=24.0.0
21
21
  Requires-Dist: typing-extensions
22
22
  Provides-Extra: bigquery
23
23
  Requires-Dist: google-cloud-bigquery-storage <3,>=2 ; extra == 'bigquery'
@@ -27,7 +27,7 @@ Requires-Dist: databricks-sql-connector[pyarrow] <5,>=3.6 ; extra == 'databricks
27
27
  Provides-Extra: dev
28
28
  Requires-Dist: duckdb <1.4,>=1.2 ; extra == 'dev'
29
29
  Requires-Dist: findspark <3,>=2 ; extra == 'dev'
30
- Requires-Dist: mypy <1.16,>=1.10.0 ; extra == 'dev'
30
+ Requires-Dist: mypy <1.17,>=1.10.0 ; extra == 'dev'
31
31
  Requires-Dist: openai <2,>=1.30 ; extra == 'dev'
32
32
  Requires-Dist: pandas-stubs <3,>=2 ; extra == 'dev'
33
33
  Requires-Dist: pandas <3,>=2 ; extra == 'dev'
@@ -37,7 +37,7 @@ Requires-Dist: pyarrow <21,>=10 ; extra == 'dev'
37
37
  Requires-Dist: pyspark <3.6,>=2 ; extra == 'dev'
38
38
  Requires-Dist: pytest-forked ; extra == 'dev'
39
39
  Requires-Dist: pytest-postgresql <8,>=6 ; extra == 'dev'
40
- Requires-Dist: pytest-xdist <3.7,>=3.6 ; extra == 'dev'
40
+ Requires-Dist: pytest-xdist <3.8,>=3.6 ; extra == 'dev'
41
41
  Requires-Dist: pytest <8.4,>=8.2.0 ; extra == 'dev'
42
42
  Requires-Dist: ruff <0.12,>=0.4.4 ; extra == 'dev'
43
43
  Requires-Dist: types-psycopg2 <3,>=2.9 ; extra == 'dev'
@@ -1,11 +1,11 @@
1
1
  sqlframe/__init__.py,sha256=SB80yLTITBXHI2GCDS6n6bN5ObHqgPjfpRPAUwxaots,3403
2
- sqlframe/_version.py,sha256=9Dhg19xsbG33VnlXESdp75HcNQAc2ar-bSzzRVx9fps,513
2
+ sqlframe/_version.py,sha256=7g8azNoGkpCE49IU2rOL3zuXv7a-Qm8z4ELFqhlkewc,513
3
3
  sqlframe/py.typed,sha256=Nqnn8clbgv-5l0PgxcTOldg8mkMKrFn4TvPL-rYUUGg,1
4
4
  sqlframe/base/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  sqlframe/base/_typing.py,sha256=b2clI5HI1zEZKB_3Msx3FeAJQyft44ubUifJwQRVXyQ,1298
6
6
  sqlframe/base/catalog.py,sha256=-YulM2BMK8MoWbXi05AsJIPxd4AuiZDBCZuk4HoeMlE,38900
7
- sqlframe/base/column.py,sha256=zDG9YT-5M7H8tDISOkJ6uMBU7Q3enTmc6d7rzZ08q40,20172
8
- sqlframe/base/dataframe.py,sha256=6L8xTdwwQCkUzpJ6K3QlCcz5zqk2QQmGzteI-1EJ23A,84374
7
+ sqlframe/base/column.py,sha256=5ZnZcn6gCCrAL53-EEHxVQWXG2oijN3RCOhlWmsjbJM,21147
8
+ sqlframe/base/dataframe.py,sha256=0diYONDlet8iZt49LC3vcmfXHAAZ2MovPL2pTXYHj2U,85974
9
9
  sqlframe/base/decorators.py,sha256=IhE5xNQDkwJHacCvulq5WpUKyKmXm7dL2A3o5WuKGP4,2131
10
10
  sqlframe/base/exceptions.py,sha256=9Uwvqn2eAkDpqm4BrRgbL61qM-GMCbJEMAW8otxO46s,370
11
11
  sqlframe/base/function_alternatives.py,sha256=dEymHSOQgUzhoYtfY5acC9AxpMoGoHXX7v6yTadKzn8,53527
@@ -34,7 +34,7 @@ sqlframe/bigquery/functions.py,sha256=MYLs6-sXXqe5o6ghJHHtEpFJlYMeyKzx9-rT3wwXlc
34
34
  sqlframe/bigquery/functions.pyi,sha256=KXgV46eZFNIXwXIhPuSJ08BG18iLQzDCQjyI3REBEXg,11925
35
35
  sqlframe/bigquery/group.py,sha256=UVBNBRTo8OqS-_cS5YwvTeJYgYxeG-d6R3kfyHmlFqw,391
36
36
  sqlframe/bigquery/readwriter.py,sha256=2uQhGe0THiLPb-_NF5jDdbizwjYJk854MuhEcnLghaE,949
37
- sqlframe/bigquery/session.py,sha256=5-SNh1sHd4Q6zPEmlinL9LLwsqlzBTqT-ZNRAFpU1_s,2931
37
+ sqlframe/bigquery/session.py,sha256=89aFgFkN7tknJUaNRP9XK0C8vyvfDymV1dDarkjkqsY,2947
38
38
  sqlframe/bigquery/table.py,sha256=pSSRFeKcStyFuE1B4uiheP22tHHq5SdQ-uuaNQpbsfI,661
39
39
  sqlframe/bigquery/types.py,sha256=KwNyuXIo-2xVVd4bZED3YrQOobKCtemlxGrJL7DrTC8,34
40
40
  sqlframe/bigquery/udf.py,sha256=ZZ1-P1zWZhQqmhBqwAxfNeKl31nDkkZgkuz7Dn28P_0,264
@@ -130,8 +130,8 @@ sqlframe/standalone/udf.py,sha256=azmgtUjHNIPs0WMVNId05SHwiYn41MKVBhKXsQJ5dmY,27
130
130
  sqlframe/standalone/window.py,sha256=6GKPzuxeSapJakBaKBeT9VpED1ACdjggDv9JRILDyV0,35
131
131
  sqlframe/testing/__init__.py,sha256=VVCosQhitU74A3NnE52O4mNtGZONapuEXcc20QmSlnQ,132
132
132
  sqlframe/testing/utils.py,sha256=PFsGZpwNUE_4-g_f43_vstTqsK0AQ2lBneb5Eb6NkFo,13008
133
- sqlframe-3.33.1.dist-info/LICENSE,sha256=VZu79YgW780qxaFJMr0t5ZgbOYEh04xWoxaWOaqIGWk,1068
134
- sqlframe-3.33.1.dist-info/METADATA,sha256=W40NdA9Zw8eWNZIQzwJEBZm0Mt-JHuezntIolna3GkE,8987
135
- sqlframe-3.33.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
136
- sqlframe-3.33.1.dist-info/top_level.txt,sha256=T0_RpoygaZSF6heeWwIDQgaP0varUdSK1pzjeJZRjM8,9
137
- sqlframe-3.33.1.dist-info/RECORD,,
133
+ sqlframe-3.35.0.dist-info/LICENSE,sha256=VZu79YgW780qxaFJMr0t5ZgbOYEh04xWoxaWOaqIGWk,1068
134
+ sqlframe-3.35.0.dist-info/METADATA,sha256=g3Jq3zH6RCoO0nlgQ2L61LabEoQYDGBDilcKykWExJ8,8987
135
+ sqlframe-3.35.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
136
+ sqlframe-3.35.0.dist-info/top_level.txt,sha256=T0_RpoygaZSF6heeWwIDQgaP0varUdSK1pzjeJZRjM8,9
137
+ sqlframe-3.35.0.dist-info/RECORD,,