dotted-notation 0.57.0__tar.gz → 0.57.2__tar.gz
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.
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/CHANGELOG.md +25 -0
- {dotted_notation-0.57.0/dotted_notation.egg-info → dotted_notation-0.57.2}/PKG-INFO +15 -2
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/README.md +14 -1
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/base.py +3 -6
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/results.py +0 -12
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/translators/core.py +17 -3
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/translators/spark.py +46 -4
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/translators/spark_pyspark.py +90 -4
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/utils.py +27 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2/dotted_notation.egg-info}/PKG-INFO +15 -2
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/pyproject.toml +2 -2
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/LICENSE +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/MANIFEST.in +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/__init__.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/__main__.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/access.pxd +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/access.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/api.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/base.pxd +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/cli/__init__.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/cli/_compat.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/cli/formats.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/cli/main.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/containers.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/engine.pxd +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/engine.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/filters.pxd +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/filters.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/grammar.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/groups.pxd +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/groups.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/matchers.pxd +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/matchers.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/native.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/predicates.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/recursive.pxd +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/recursive.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/transforms.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/translators/__init__.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/translators/sql.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/translators/sql_pg.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/utypes.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/wrappers.pxd +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted/wrappers.py +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted_notation.egg-info/SOURCES.txt +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted_notation.egg-info/dependency_links.txt +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted_notation.egg-info/entry_points.txt +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted_notation.egg-info/requires.txt +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted_notation.egg-info/top_level.txt +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/setup.cfg +0 -0
- {dotted_notation-0.57.0 → dotted_notation-0.57.2}/setup.py +0 -0
|
@@ -3,6 +3,31 @@
|
|
|
3
3
|
All notable changes to `dotted` are recorded here. Versions prior to
|
|
4
4
|
the ones listed are omitted — browse git history for earlier entries.
|
|
5
5
|
|
|
6
|
+
## [0.57.2]
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
- A list, set or dict bound to a substitution no longer raises
|
|
10
|
+
`TypeError: unhashable type` when the path is parsed: `a=$(b)`
|
|
11
|
+
compares with the bound list, and `a|in:$(b)=True` tests containment
|
|
12
|
+
in it, or in a bound dict's keys, which need not sort against each
|
|
13
|
+
other.
|
|
14
|
+
|
|
15
|
+
## [0.57.1]
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
- `sparkize` reads a path under a `Column` the caller holds: a
|
|
19
|
+
substitution at a read's head, `$(item).id`, is bound in `build` to a
|
|
20
|
+
Column, which the path then reads from, or to a column's name.
|
|
21
|
+
`r.typed(column, dtype)` (`dotted.translators.spark.typed`) carries
|
|
22
|
+
the type of a Column no session resolves, a higher-order function's
|
|
23
|
+
lambda argument, and works for any Column binding (#83).
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
- `sparkize`: a `Column` bound at a path's head with `bindings=` is read
|
|
27
|
+
from; it was taken for a column's name and read NULL. A Column where
|
|
28
|
+
a name is needed (a write's column, a table, a filter key) raises
|
|
29
|
+
(#83).
|
|
30
|
+
|
|
6
31
|
## [0.57.0]
|
|
7
32
|
|
|
8
33
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dotted_notation
|
|
3
|
-
Version: 0.57.
|
|
3
|
+
Version: 0.57.2
|
|
4
4
|
Summary: Dotted notation for safe nested data traversal with optional chaining, pattern matching, and transforms
|
|
5
5
|
Author-email: Frey Waid <logophage1@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -4472,6 +4472,19 @@ A `Column` binding is compared by its type, which `build` reads in the
|
|
|
4472
4472
|
active session: `r.build(r.where, schema=df.schema,
|
|
4473
4473
|
min_age=F.col('floor'))`.
|
|
4474
4474
|
|
|
4475
|
+
A substitution at a path's head starts the read at what `build` binds
|
|
4476
|
+
it to: a `Column`, or a column's name. A higher-order function's lambda
|
|
4477
|
+
argument is a Column no session can type, so `r.typed(column, dtype)`
|
|
4478
|
+
carries its type:
|
|
4479
|
+
|
|
4480
|
+
r = dotted.sparkize('$(item).id')
|
|
4481
|
+
elem = df.schema['xs'].dataType.elementType
|
|
4482
|
+
df.select(F.transform('xs', lambda e: r.build(
|
|
4483
|
+
r.select, schema=df.schema, item=r.typed(e, elem))))
|
|
4484
|
+
|
|
4485
|
+
`r.typed` is `dotted.translators.spark.typed`, and works for any Column
|
|
4486
|
+
binding. A write (`as_update`) can't start at a Column.
|
|
4487
|
+
|
|
4475
4488
|
### Composing fragments
|
|
4476
4489
|
|
|
4477
4490
|
A `Column` can't hold a placeholder, so `r.where` is a
|
|
@@ -4580,7 +4593,7 @@ Not yet supported (`TranslationError`):
|
|
|
4580
4593
|
`dotted.translators.flavors()` lists them.
|
|
4581
4594
|
- `bindings` — resolve substitutions at sparkize time. Path-position
|
|
4582
4595
|
substitutions must be resolved here, row indexes and slice bounds
|
|
4583
|
-
included.
|
|
4596
|
+
included, but for one at a read's head, which `build` may bind.
|
|
4584
4597
|
- `root` — `'column'` (default): the first segment is a column.
|
|
4585
4598
|
`'table'`: a [table search](#sparkize-table-search).
|
|
4586
4599
|
|
|
@@ -4422,6 +4422,19 @@ A `Column` binding is compared by its type, which `build` reads in the
|
|
|
4422
4422
|
active session: `r.build(r.where, schema=df.schema,
|
|
4423
4423
|
min_age=F.col('floor'))`.
|
|
4424
4424
|
|
|
4425
|
+
A substitution at a path's head starts the read at what `build` binds
|
|
4426
|
+
it to: a `Column`, or a column's name. A higher-order function's lambda
|
|
4427
|
+
argument is a Column no session can type, so `r.typed(column, dtype)`
|
|
4428
|
+
carries its type:
|
|
4429
|
+
|
|
4430
|
+
r = dotted.sparkize('$(item).id')
|
|
4431
|
+
elem = df.schema['xs'].dataType.elementType
|
|
4432
|
+
df.select(F.transform('xs', lambda e: r.build(
|
|
4433
|
+
r.select, schema=df.schema, item=r.typed(e, elem))))
|
|
4434
|
+
|
|
4435
|
+
`r.typed` is `dotted.translators.spark.typed`, and works for any Column
|
|
4436
|
+
binding. A write (`as_update`) can't start at a Column.
|
|
4437
|
+
|
|
4425
4438
|
### Composing fragments
|
|
4426
4439
|
|
|
4427
4440
|
A `Column` can't hold a placeholder, so `r.where` is a
|
|
@@ -4530,7 +4543,7 @@ Not yet supported (`TranslationError`):
|
|
|
4530
4543
|
`dotted.translators.flavors()` lists them.
|
|
4531
4544
|
- `bindings` — resolve substitutions at sparkize time. Path-position
|
|
4532
4545
|
substitutions must be resolved here, row indexes and slice bounds
|
|
4533
|
-
included.
|
|
4546
|
+
included, but for one at a read's head, which `build` may bind.
|
|
4534
4547
|
- `root` — `'column'` (default): the first segment is a column.
|
|
4535
4548
|
`'table'`: a [table search](#sparkize-table-search).
|
|
4536
4549
|
|
|
@@ -4,6 +4,7 @@ Base classes, sentinels, and infrastructure for the dotted element system.
|
|
|
4
4
|
import collections
|
|
5
5
|
import pyparsing as pp
|
|
6
6
|
|
|
7
|
+
from . import utils
|
|
7
8
|
from .utypes import marker, ANY, BRANCH_CUT, BRANCH_SOFTCUT, resolve_types # noqa: F401
|
|
8
9
|
|
|
9
10
|
|
|
@@ -133,7 +134,7 @@ class Op:
|
|
|
133
134
|
def __repr__(self):
|
|
134
135
|
return f'{self.__class__.__name__}:{self.args}'
|
|
135
136
|
def __hash__(self):
|
|
136
|
-
return
|
|
137
|
+
return utils.hash_of(self.args)
|
|
137
138
|
def __eq__(self, op):
|
|
138
139
|
return self.__class__ == op.__class__ and self.args == op.args
|
|
139
140
|
def resolve(self, bindings, partial=False):
|
|
@@ -690,11 +691,7 @@ class Transform(Op):
|
|
|
690
691
|
return self.operator()
|
|
691
692
|
|
|
692
693
|
def __hash__(self):
|
|
693
|
-
|
|
694
|
-
return hash(('transform', self.name, self.params))
|
|
695
|
-
except TypeError:
|
|
696
|
-
from .results import Dotted
|
|
697
|
-
return hash(('transform', self.name, Dotted._hashable(self.params)))
|
|
694
|
+
return utils.hash_of(('transform', self.name, self.params))
|
|
698
695
|
|
|
699
696
|
def __eq__(self, other):
|
|
700
697
|
return (isinstance(other, Transform)
|
|
@@ -91,18 +91,6 @@ class Dotted:
|
|
|
91
91
|
return ''.join(parts), Dotted({'ops': self.ops[:-1]})
|
|
92
92
|
def __repr__(self):
|
|
93
93
|
return f'{self.__class__.__name__}({list(self.ops)})'
|
|
94
|
-
@staticmethod
|
|
95
|
-
def _hashable(obj):
|
|
96
|
-
"""
|
|
97
|
-
Recursively convert unhashable types to hashable equivalents.
|
|
98
|
-
"""
|
|
99
|
-
if utils.is_list_like(obj):
|
|
100
|
-
return tuple(Dotted._hashable(x) for x in obj)
|
|
101
|
-
if utils.is_set_like(obj):
|
|
102
|
-
return frozenset(Dotted._hashable(x) for x in obj)
|
|
103
|
-
if utils.is_dict_like(obj):
|
|
104
|
-
return tuple(sorted((k, Dotted._hashable(v)) for k, v in utils.mapping_entries(obj)))
|
|
105
|
-
return obj
|
|
106
94
|
def __hash__(self):
|
|
107
95
|
if self._hash is None:
|
|
108
96
|
# not hash(self.ops): a Dotted must not collide with its own ops tuple
|
|
@@ -507,7 +507,7 @@ class _Column(Hooks):
|
|
|
507
507
|
"""
|
|
508
508
|
|
|
509
509
|
def key(self, op, t, rest, row):
|
|
510
|
-
col = t.
|
|
510
|
+
col = t._head_column(op)
|
|
511
511
|
return t._result(**t._walk(col, (), rest))
|
|
512
512
|
|
|
513
513
|
# any other first op is a column key or raises in `_column_name`
|
|
@@ -517,7 +517,7 @@ class _Column(Hooks):
|
|
|
517
517
|
# `status = "active"`: one op, a guard wrapping the column key
|
|
518
518
|
if rest:
|
|
519
519
|
raise TranslationError('path continues after column-level guard')
|
|
520
|
-
col = t.
|
|
520
|
+
col = t._head_column(op.inner)
|
|
521
521
|
return t._result(select=col, where=t._scalar_predicate(op, col))
|
|
522
522
|
|
|
523
523
|
def group(self, op, kind, branches, cuts, softs, t, rest, row):
|
|
@@ -734,7 +734,7 @@ class _Name(Hooks):
|
|
|
734
734
|
raise TranslationError(f'unsupported {position} matcher: {type(m).__name__}')
|
|
735
735
|
|
|
736
736
|
def const(self, m, t, position):
|
|
737
|
-
return
|
|
737
|
+
return t._named(m.value, position)
|
|
738
738
|
|
|
739
739
|
def subst(self, m, t, position):
|
|
740
740
|
raise TranslationError(f'unresolved substitution in {position} position')
|
|
@@ -1165,6 +1165,20 @@ class Translator:
|
|
|
1165
1165
|
"""
|
|
1166
1166
|
return op.translated(_COLUMN_NAME, self)
|
|
1167
1167
|
|
|
1168
|
+
def _head_column(self, op):
|
|
1169
|
+
"""
|
|
1170
|
+
The column the first op of a read names, as `_column` gives it.
|
|
1171
|
+
A flavor that can start a read elsewhere overrides this.
|
|
1172
|
+
"""
|
|
1173
|
+
return self._column(self._column_name(op))
|
|
1174
|
+
|
|
1175
|
+
def _named(self, value, position):
|
|
1176
|
+
"""
|
|
1177
|
+
The name a matcher's `value` gives in `position`. A flavor
|
|
1178
|
+
overrides this to refuse a value that names nothing.
|
|
1179
|
+
"""
|
|
1180
|
+
return str(value)
|
|
1181
|
+
|
|
1168
1182
|
def _name(self, matcher, position):
|
|
1169
1183
|
"""
|
|
1170
1184
|
The name `matcher` holds in `position` (a column, a table, a
|
|
@@ -114,6 +114,38 @@ class ColumnFragment:
|
|
|
114
114
|
return ColumnFragment(lambda env: ~mine(env), self.unbound)
|
|
115
115
|
|
|
116
116
|
|
|
117
|
+
# ---- Typed columns --------------------------------------------------
|
|
118
|
+
|
|
119
|
+
class TypedColumn:
|
|
120
|
+
"""
|
|
121
|
+
A Spark `Column` with its Spark type, `dtype`, as a binding. `build`
|
|
122
|
+
reads a Column binding's type in the active session, against the
|
|
123
|
+
schema; this carries the type of one no session resolves there, a
|
|
124
|
+
higher-order function's lambda argument.
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
__slots__ = ('column', 'dtype')
|
|
128
|
+
|
|
129
|
+
def __init__(self, column, dtype):
|
|
130
|
+
self.column = column
|
|
131
|
+
self.dtype = dtype
|
|
132
|
+
|
|
133
|
+
def __repr__(self):
|
|
134
|
+
return f'TypedColumn({self.column!r}, {self.dtype!r})'
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def typed(column, dtype):
|
|
138
|
+
"""
|
|
139
|
+
The Column `column` as a binding of the Spark type `dtype`:
|
|
140
|
+
|
|
141
|
+
r = sparkize('$(item).id', flavor='pyspark')
|
|
142
|
+
elem = df.schema['xs'].dataType.elementType
|
|
143
|
+
df.select(F.transform('xs', lambda e: r.build(
|
|
144
|
+
r.select, schema=df.schema, item=typed(e, elem))))
|
|
145
|
+
"""
|
|
146
|
+
return TypedColumn(column, dtype)
|
|
147
|
+
|
|
148
|
+
|
|
117
149
|
# ---- Flavor registry ------------------------------------------------
|
|
118
150
|
|
|
119
151
|
# flavor name (str) → SparkResolver subclass. Populated by `@flavor`
|
|
@@ -242,6 +274,9 @@ class SparkResolver(collections.abc.Mapping):
|
|
|
242
274
|
|
|
243
275
|
# ---- rendering ----
|
|
244
276
|
|
|
277
|
+
# `r.typed(column, dtype)`: a Column binding with its type
|
|
278
|
+
typed = staticmethod(typed)
|
|
279
|
+
|
|
245
280
|
def rows(self, df, **bindings):
|
|
246
281
|
"""
|
|
247
282
|
The rows a table search reads, from the table's DataFrame `df`,
|
|
@@ -270,7 +305,13 @@ class SparkResolver(collections.abc.Mapping):
|
|
|
270
305
|
field or a map's key, an int or a string.
|
|
271
306
|
|
|
272
307
|
A binding is a Python value, compared as Python compares it, or
|
|
273
|
-
a Spark Column, read by its type in the active session
|
|
308
|
+
a Spark Column, read by its type in the active session;
|
|
309
|
+
`typed(column, dtype)` gives the type of one no session
|
|
310
|
+
resolves, a lambda's argument.
|
|
311
|
+
|
|
312
|
+
A substitution at a path's head, `$(item).id`, is bound here
|
|
313
|
+
too: to a Column, which the path then reads from, or to a
|
|
314
|
+
column's name.
|
|
274
315
|
|
|
275
316
|
Raises `TranslationError` on:
|
|
276
317
|
- a non-fragment argument
|
|
@@ -317,9 +358,10 @@ def sparkize(path, *, flavor, bindings=None, root='column'):
|
|
|
317
358
|
'pyspark'.
|
|
318
359
|
bindings — optional mapping/list used to resolve substitutions
|
|
319
360
|
at sparkize time. Path-position substitutions must
|
|
320
|
-
be resolved here or `TranslationError` is raised
|
|
321
|
-
|
|
322
|
-
|
|
361
|
+
be resolved here or `TranslationError` is raised,
|
|
362
|
+
but for one at the path's head, the column a read
|
|
363
|
+
starts at. That one and unresolved value-position
|
|
364
|
+
substitutions appear in `r.unbound`.
|
|
323
365
|
root — `'column'` (default): the path's first segment is a
|
|
324
366
|
column of the row. `'table'`: its leading keys name
|
|
325
367
|
a DataFrame or table, a row step (`[*]`, `[*&…]`,
|
|
@@ -26,6 +26,7 @@ import re
|
|
|
26
26
|
import sys
|
|
27
27
|
|
|
28
28
|
from . import core
|
|
29
|
+
from . import spark
|
|
29
30
|
from .core import Hooks, TranslationError, Translator
|
|
30
31
|
from .spark import ColumnFragment, SparkResolver, flavor, _merged
|
|
31
32
|
|
|
@@ -1452,8 +1453,8 @@ def _compared(node, op, value, env):
|
|
|
1452
1453
|
"""
|
|
1453
1454
|
if op == '!=':
|
|
1454
1455
|
return _not(_compared(node, '=', value, env))
|
|
1455
|
-
if
|
|
1456
|
-
return _against(node, op,
|
|
1456
|
+
if _is_held(value):
|
|
1457
|
+
return _against(node, op, _held_node(value, env))
|
|
1457
1458
|
if value is None:
|
|
1458
1459
|
if op != '=':
|
|
1459
1460
|
return False
|
|
@@ -1613,6 +1614,24 @@ def _is_column(value):
|
|
|
1613
1614
|
return type(value).__name__ == 'Column' and type(value).__module__.startswith('pyspark')
|
|
1614
1615
|
|
|
1615
1616
|
|
|
1617
|
+
def _is_held(value):
|
|
1618
|
+
"""
|
|
1619
|
+
True for a binding that is a Column: a Spark Column, or one with its
|
|
1620
|
+
type (`spark.typed`).
|
|
1621
|
+
"""
|
|
1622
|
+
return _is_column(value) or isinstance(value, spark.TypedColumn)
|
|
1623
|
+
|
|
1624
|
+
|
|
1625
|
+
def _held_node(value, env):
|
|
1626
|
+
"""
|
|
1627
|
+
The node a Column binding is: a typed one by the type it carries,
|
|
1628
|
+
a bare one by the type the active session reads.
|
|
1629
|
+
"""
|
|
1630
|
+
if isinstance(value, spark.TypedColumn):
|
|
1631
|
+
return _Node(value.column, value.dtype)
|
|
1632
|
+
return _Node(value, _column_type(value, env))
|
|
1633
|
+
|
|
1634
|
+
|
|
1616
1635
|
def _column_type(col, env):
|
|
1617
1636
|
"""
|
|
1618
1637
|
The Spark type of a Column handed in as a binding, read against the
|
|
@@ -2153,6 +2172,16 @@ def _column_node(env, name):
|
|
|
2153
2172
|
return None
|
|
2154
2173
|
|
|
2155
2174
|
|
|
2175
|
+
def _head_node(value, env):
|
|
2176
|
+
"""
|
|
2177
|
+
The node a read starts at for what its head holds: a Column binding
|
|
2178
|
+
itself, or the column anything else names.
|
|
2179
|
+
"""
|
|
2180
|
+
if _is_held(value):
|
|
2181
|
+
return _held_node(value, env)
|
|
2182
|
+
return _column_node(env, str(value))
|
|
2183
|
+
|
|
2184
|
+
|
|
2156
2185
|
def _node_of(frag):
|
|
2157
2186
|
"""
|
|
2158
2187
|
The node maker of a fragment that reads one.
|
|
@@ -2206,7 +2235,7 @@ class _Written:
|
|
|
2206
2235
|
self.column = column
|
|
2207
2236
|
|
|
2208
2237
|
def node(self, env):
|
|
2209
|
-
return
|
|
2238
|
+
return _held_node(self.column, env)
|
|
2210
2239
|
|
|
2211
2240
|
|
|
2212
2241
|
def _wfail(what, node):
|
|
@@ -2919,6 +2948,25 @@ class PySparkMixin(Translator):
|
|
|
2919
2948
|
"""
|
|
2920
2949
|
return _Typed(lambda env: _column_node(env, name))
|
|
2921
2950
|
|
|
2951
|
+
def _head_column(self, op):
|
|
2952
|
+
"""
|
|
2953
|
+
The column a read starts at: the one its first op names, or
|
|
2954
|
+
what a substitution there holds, a Column the caller has or a
|
|
2955
|
+
column's name.
|
|
2956
|
+
"""
|
|
2957
|
+
held = op.translated(_HEAD, self)
|
|
2958
|
+
if held is not None:
|
|
2959
|
+
return held
|
|
2960
|
+
return super()._head_column(op)
|
|
2961
|
+
|
|
2962
|
+
def _named(self, value, position):
|
|
2963
|
+
"""
|
|
2964
|
+
A name, but for a Column: only a read's head starts at one.
|
|
2965
|
+
"""
|
|
2966
|
+
if _is_held(value):
|
|
2967
|
+
raise TranslationError(f'a Column in {position} position not supported')
|
|
2968
|
+
return super()._named(value, position)
|
|
2969
|
+
|
|
2922
2970
|
def _all_columns(self):
|
|
2923
2971
|
"""
|
|
2924
2972
|
`*`.
|
|
@@ -3184,7 +3232,7 @@ class PySparkMixin(Translator):
|
|
|
3184
3232
|
write touches, by name, to its new value, for `df.withColumns`.
|
|
3185
3233
|
`value` is a literal, or a Spark Column read by its type.
|
|
3186
3234
|
"""
|
|
3187
|
-
column = value if
|
|
3235
|
+
column = value if _is_held(value) else None
|
|
3188
3236
|
self._wwritten = _Written(column)
|
|
3189
3237
|
self._wunbound = {}
|
|
3190
3238
|
pairs = self._translate_write(self._ops, self._root, value, column is None)
|
|
@@ -3423,6 +3471,42 @@ class _KeyStep(Hooks):
|
|
|
3423
3471
|
raise TranslationError('references inside pattern paths not supported yet')
|
|
3424
3472
|
|
|
3425
3473
|
|
|
3474
|
+
class _Head(Hooks):
|
|
3475
|
+
"""
|
|
3476
|
+
The first op of a read as the node a substitution there holds, a
|
|
3477
|
+
fragment: one bound to a Column at sparkize, or one left for
|
|
3478
|
+
`build`. None for any other, which names a column.
|
|
3479
|
+
"""
|
|
3480
|
+
|
|
3481
|
+
def other(self, op, t):
|
|
3482
|
+
return None
|
|
3483
|
+
|
|
3484
|
+
def key(self, op, t):
|
|
3485
|
+
return op.op.translated(_HEAD_MATCHER, t)
|
|
3486
|
+
|
|
3487
|
+
def slot(self, op, t):
|
|
3488
|
+
return None
|
|
3489
|
+
|
|
3490
|
+
|
|
3491
|
+
class _HeadMatcher(Hooks):
|
|
3492
|
+
"""
|
|
3493
|
+
A key's matcher at a read's head, as `_Head` gives it.
|
|
3494
|
+
"""
|
|
3495
|
+
|
|
3496
|
+
def other(self, m, t):
|
|
3497
|
+
return None
|
|
3498
|
+
|
|
3499
|
+
def const(self, m, t):
|
|
3500
|
+
value = m.value
|
|
3501
|
+
if not _is_held(value):
|
|
3502
|
+
return None
|
|
3503
|
+
return _Typed(lambda env: _held_node(value, env))
|
|
3504
|
+
|
|
3505
|
+
def subst(self, m, t):
|
|
3506
|
+
name = m.value
|
|
3507
|
+
return _Typed(lambda env: _head_node(env[name], env), {name: name})
|
|
3508
|
+
|
|
3509
|
+
|
|
3426
3510
|
class _Comparison(Hooks):
|
|
3427
3511
|
"""
|
|
3428
3512
|
A guard's or filter's value as `(test(node, env), unbound)`: Python's
|
|
@@ -3531,6 +3615,8 @@ class _FilterKeyStep(Hooks):
|
|
|
3531
3615
|
_STEPS = _Steps()
|
|
3532
3616
|
_KEY_STEP = _KeyStep()
|
|
3533
3617
|
_COMPARISON = _Comparison()
|
|
3618
|
+
_HEAD = _Head()
|
|
3619
|
+
_HEAD_MATCHER = _HeadMatcher()
|
|
3534
3620
|
_FILTER_PRED = _FilterPred()
|
|
3535
3621
|
_FILTER_KEY_STEP = _FilterKeyStep()
|
|
3536
3622
|
|
|
@@ -189,6 +189,33 @@ def mapping_entries(node):
|
|
|
189
189
|
return ((k, node[k]) for k in node)
|
|
190
190
|
|
|
191
191
|
|
|
192
|
+
def hashable(obj):
|
|
193
|
+
"""
|
|
194
|
+
obj with its unhashable containers, at any depth, swapped for hashable
|
|
195
|
+
ones: a list-like for a tuple, a set-like for a frozenset, a dict-like
|
|
196
|
+
for a frozenset of its entries, which no more depends on their order
|
|
197
|
+
than the dict does and asks nothing of its keys but a hash.
|
|
198
|
+
"""
|
|
199
|
+
if is_list_like(obj):
|
|
200
|
+
return tuple(hashable(x) for x in obj)
|
|
201
|
+
if is_set_like(obj):
|
|
202
|
+
return frozenset(hashable(x) for x in obj)
|
|
203
|
+
if is_dict_like(obj):
|
|
204
|
+
return frozenset((k, hashable(v)) for k, v in mapping_entries(obj))
|
|
205
|
+
return obj
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def hash_of(obj):
|
|
209
|
+
"""
|
|
210
|
+
The hash of obj, or of hashable(obj) when obj holds something
|
|
211
|
+
unhashable, such as a list bound to a substitution.
|
|
212
|
+
"""
|
|
213
|
+
try:
|
|
214
|
+
return hash(obj)
|
|
215
|
+
except TypeError:
|
|
216
|
+
return hash(hashable(obj))
|
|
217
|
+
|
|
218
|
+
|
|
192
219
|
def entries(node):
|
|
193
220
|
"""
|
|
194
221
|
node as a lazy stream of (key, value) entries, by its interface, or
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dotted_notation
|
|
3
|
-
Version: 0.57.
|
|
3
|
+
Version: 0.57.2
|
|
4
4
|
Summary: Dotted notation for safe nested data traversal with optional chaining, pattern matching, and transforms
|
|
5
5
|
Author-email: Frey Waid <logophage1@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -4472,6 +4472,19 @@ A `Column` binding is compared by its type, which `build` reads in the
|
|
|
4472
4472
|
active session: `r.build(r.where, schema=df.schema,
|
|
4473
4473
|
min_age=F.col('floor'))`.
|
|
4474
4474
|
|
|
4475
|
+
A substitution at a path's head starts the read at what `build` binds
|
|
4476
|
+
it to: a `Column`, or a column's name. A higher-order function's lambda
|
|
4477
|
+
argument is a Column no session can type, so `r.typed(column, dtype)`
|
|
4478
|
+
carries its type:
|
|
4479
|
+
|
|
4480
|
+
r = dotted.sparkize('$(item).id')
|
|
4481
|
+
elem = df.schema['xs'].dataType.elementType
|
|
4482
|
+
df.select(F.transform('xs', lambda e: r.build(
|
|
4483
|
+
r.select, schema=df.schema, item=r.typed(e, elem))))
|
|
4484
|
+
|
|
4485
|
+
`r.typed` is `dotted.translators.spark.typed`, and works for any Column
|
|
4486
|
+
binding. A write (`as_update`) can't start at a Column.
|
|
4487
|
+
|
|
4475
4488
|
### Composing fragments
|
|
4476
4489
|
|
|
4477
4490
|
A `Column` can't hold a placeholder, so `r.where` is a
|
|
@@ -4580,7 +4593,7 @@ Not yet supported (`TranslationError`):
|
|
|
4580
4593
|
`dotted.translators.flavors()` lists them.
|
|
4581
4594
|
- `bindings` — resolve substitutions at sparkize time. Path-position
|
|
4582
4595
|
substitutions must be resolved here, row indexes and slice bounds
|
|
4583
|
-
included.
|
|
4596
|
+
included, but for one at a read's head, which `build` may bind.
|
|
4584
4597
|
- `root` — `'column'` (default): the first segment is a column.
|
|
4585
4598
|
`'table'`: a [table search](#sparkize-table-search).
|
|
4586
4599
|
|
|
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "dotted_notation"
|
|
9
|
-
version = "0.57.
|
|
9
|
+
version = "0.57.2"
|
|
10
10
|
description = "Dotted notation for safe nested data traversal with optional chaining, pattern matching, and transforms"
|
|
11
11
|
readme = "README.md"
|
|
12
12
|
requires-python = ">=3.6"
|
|
@@ -84,6 +84,6 @@ include = ["dotted*"]
|
|
|
84
84
|
[tool.cibuildwheel]
|
|
85
85
|
# Compiled wheels for CPython 3.11-3.15 (the versions are listed in the
|
|
86
86
|
# publish workflow, one job each); everything else installs the pure wheel.
|
|
87
|
-
skip
|
|
87
|
+
# PyPy needs no skip: cibuildwheel builds it only where `enable` asks.
|
|
88
88
|
test-requires = "pytest"
|
|
89
89
|
test-command = "python -c \"import dotted; assert dotted.native.active(), 'the compiled engine did not load'\" && pytest {project}/tests -q -p no:cacheprovider --import-mode=importlib"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dotted_notation-0.57.0 → dotted_notation-0.57.2}/dotted_notation.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|