earthengine-api 1.6.15__py3-none-any.whl → 1.7.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.

Potentially problematic release.


This version of earthengine-api might be problematic. Click here for more details.

ee/serializer.py CHANGED
@@ -4,7 +4,7 @@ import collections
4
4
  import datetime
5
5
  import hashlib
6
6
  import json
7
- from typing import Any, Optional
7
+ from typing import Any
8
8
 
9
9
  from ee import _cloud_api_utils
10
10
  from ee import _utils
@@ -32,7 +32,7 @@ def DatetimeToMicroseconds(date: datetime.datetime) -> int:
32
32
 
33
33
  class Serializer:
34
34
  """A serializer for EE object trees."""
35
- unbound_name: Optional[str]
35
+ unbound_name: str | None
36
36
 
37
37
  # Whether the encoding should factor out shared subtrees.
38
38
  _is_compound: bool
@@ -48,7 +48,7 @@ class Serializer:
48
48
  self,
49
49
  is_compound: bool = True,
50
50
  for_cloud_api: bool = False,
51
- unbound_name: Optional[str] = None,
51
+ unbound_name: str | None = None,
52
52
  ):
53
53
  """Constructs a serializer.
54
54
 
@@ -280,7 +280,7 @@ def encode(
280
280
  obj: Any,
281
281
  is_compound: bool = True,
282
282
  for_cloud_api: bool = True,
283
- unbound_name: Optional[str] = None,
283
+ unbound_name: str | None = None,
284
284
  ) -> Any:
285
285
  """Serialize an object to a JSON-compatible structure for API calls.
286
286
 
@@ -358,7 +358,7 @@ class _ExpressionOptimizer:
358
358
  - Collapse dicts and arrays of constants to constant dicts/arrays.
359
359
  """
360
360
 
361
- def __init__(self, result: Any, values: Optional[Any] = None):
361
+ def __init__(self, result: Any, values: Any | None = None):
362
362
  """Builds an ExpressionOptimizer.
363
363
 
364
364
  Args:
@@ -385,7 +385,7 @@ class _ExpressionOptimizer:
385
385
  reference_counts = collections.defaultdict(int)
386
386
  reference_counts[self._result] += 1
387
387
 
388
- def _contained_reference(value: Any) -> Optional[Any]:
388
+ def _contained_reference(value: Any) -> Any | None:
389
389
  """Gets a contained reference from a ValueNode, if there is one."""
390
390
  if 'functionDefinitionValue' in value:
391
391
  return value['functionDefinitionValue']['body']
ee/table_converter.py CHANGED
@@ -1,7 +1,7 @@
1
1
  """Converters used in the table data fetching methods."""
2
2
 
3
3
  from collections.abc import Iterator
4
- from typing import Any, Optional, Union
4
+ from typing import Any
5
5
 
6
6
 
7
7
  class TableConverter:
@@ -59,8 +59,8 @@ _TABLE_DATA_CONVERTERS: dict[str, type[TableConverter]] = {
59
59
 
60
60
 
61
61
  def from_file_format(
62
- file_format: Union[str, TableConverter]
63
- ) -> Optional[TableConverter]:
62
+ file_format: str | TableConverter
63
+ ) -> TableConverter | None:
64
64
  if isinstance(file_format, TableConverter):
65
65
  return file_format
66
66
  if file_format in _TABLE_DATA_CONVERTERS:
ee/tests/batch_test.py CHANGED
@@ -2,7 +2,7 @@
2
2
  """Test for the ee.batch module."""
3
3
 
4
4
  import json
5
- from typing import Any, Optional
5
+ from typing import Any
6
6
  import unittest
7
7
  from unittest import mock
8
8
 
@@ -201,8 +201,8 @@ class ExportTest(unittest.TestCase):
201
201
  class BatchTestCase(apitestcase.ApiTestCase):
202
202
  """A test case for batch functionality."""
203
203
 
204
- start_call_params: Optional[Any]
205
- update_call_params: Optional[Any]
204
+ start_call_params: Any | None
205
+ update_call_params: Any | None
206
206
 
207
207
  def setUp(self):
208
208
  super().setUp()
@@ -47,6 +47,10 @@ class CollectionTestCase(apitestcase.ApiTestCase):
47
47
 
48
48
  # We don't allow empty filters.
49
49
  self.assertRaises(Exception, collection.filter)
50
+ with self.assertRaisesRegex(ee.EEException, 'Empty filters.'):
51
+ collection.filter(None) # pytype: disable=wrong-arg-types
52
+ with self.assertRaisesRegex(ee.EEException, 'Empty filters.'):
53
+ collection.filter('')
50
54
 
51
55
  filtered = collection.filter(ee.Filter.eq('foo', 1))
52
56
  self.assertEqual(ee.ApiFunction.lookup('Collection.filter'), filtered.func)
@@ -75,6 +79,37 @@ class CollectionTestCase(apitestcase.ApiTestCase):
75
79
  collection.filter(ee.Filter.eq('foo', 13)),
76
80
  collection.filterMetadata('foo', 'equals', 13))
77
81
 
82
+ def test_load_table(self):
83
+ """Verifies Collection.loadTable()."""
84
+ table_id = 'a/table/id'
85
+ geometry_column = 'geom'
86
+ version = 123
87
+ result = ee.Collection.loadTable(
88
+ tableId=table_id, geometryColumn=geometry_column, version=version
89
+ )
90
+ self.assertEqual(ee.ApiFunction.lookup('Collection.loadTable'), result.func)
91
+ self.assertEqual(
92
+ {
93
+ 'tableId': ee.String(table_id),
94
+ 'geometryColumn': ee.String(geometry_column),
95
+ 'version': ee.Number(version),
96
+ },
97
+ result.args,
98
+ )
99
+ self.assertIsInstance(result, ee.FeatureCollection)
100
+
101
+ result2 = ee.Collection.loadTable(tableId=table_id)
102
+ self.assertEqual(ee.ApiFunction.lookup('Collection.loadTable'), result2.func)
103
+ self.assertEqual(
104
+ {
105
+ 'tableId': ee.String(table_id),
106
+ 'geometryColumn': None,
107
+ 'version': None,
108
+ },
109
+ result2.args,
110
+ )
111
+ self.assertIsInstance(result2, ee.FeatureCollection)
112
+
78
113
  def test_mapping(self):
79
114
  """Verifies the behavior of the map() method."""
80
115
  collection = ee.ImageCollection('foo')
ee/tests/data_test.py CHANGED
@@ -2,7 +2,7 @@
2
2
  """Test for the ee.data module."""
3
3
 
4
4
  import json
5
- from typing import Any, Optional
5
+ from typing import Any
6
6
  from unittest import mock
7
7
 
8
8
  import googleapiclient
@@ -28,7 +28,7 @@ def NotFoundError() -> googleapiclient.errors.HttpError:
28
28
 
29
29
 
30
30
  def NewFolderAsset(
31
- name: str, quota: Optional[dict[str, int]] = None
31
+ name: str, quota: dict[str, int] | None = None
32
32
  ) -> dict[str, Any]:
33
33
  return {
34
34
  'type': 'FOLDER',
@@ -66,7 +66,9 @@ class DataTest(unittest.TestCase):
66
66
  mock_install_cloud_api_resource.assert_called_once()
67
67
 
68
68
  @mock.patch.object(ee.data, '_install_cloud_api_resource', return_value=None)
69
- def test_initialize_with_project(self, unused_mock_install_cloud_api_resource):
69
+ def test_initialize_with_project(
70
+ self, unused_mock_install_cloud_api_resource
71
+ ):
70
72
  ee.data.initialize(project='my-project')
71
73
 
72
74
  self.assertTrue(ee.data.is_initialized())
@@ -396,6 +396,31 @@ class NumberTest(apitestcase.ApiTestCase):
396
396
  result = json.loads(expression.serialize())
397
397
  self.assertEqual(expect, result)
398
398
 
399
+ def test_expression(self):
400
+ expression = ee.Number.expression('1 + 2')
401
+ self.assertIsInstance(expression, ee.Number)
402
+ self.assertEqual(
403
+ ee.ApiFunction.lookup('Number.expression'), expression.func
404
+ )
405
+
406
+ expect = make_expression_graph({
407
+ 'arguments': {'expression': {'constantValue': '1 + 2'}},
408
+ 'functionName': 'Number.expression',
409
+ })
410
+ result = json.loads(expression.serialize())
411
+ self.assertEqual(expect, result)
412
+
413
+ expression_vars = ee.Number.expression('a + b', {'a': 1, 'b': 2})
414
+ expect_vars = make_expression_graph({
415
+ 'arguments': {
416
+ 'expression': {'constantValue': 'a + b'},
417
+ 'vars': {'constantValue': {'a': 1, 'b': 2}},
418
+ },
419
+ 'functionName': 'Number.expression',
420
+ })
421
+ result_vars = json.loads(expression_vars.serialize())
422
+ self.assertEqual(expect_vars, result_vars)
423
+
399
424
  def test_first(self):
400
425
  expect = make_expression_graph({
401
426
  'arguments': {
@@ -795,7 +820,21 @@ class NumberTest(apitestcase.ApiTestCase):
795
820
  result = json.loads(expression.serialize())
796
821
  self.assertEqual(expect, result)
797
822
 
798
- # TODO: test_parse.
823
+ def test_parse(self):
824
+ expect = make_expression_graph({
825
+ 'arguments': {
826
+ 'input': {'constantValue': '1'},
827
+ 'radix': {'constantValue': 2},
828
+ },
829
+ 'functionName': 'Number.parse',
830
+ })
831
+ expression = ee.Number.parse('1', 2)
832
+ result = json.loads(expression.serialize())
833
+ self.assertEqual(expect, result)
834
+
835
+ expression = ee.Number.parse(input='1', radix=2)
836
+ result = json.loads(expression.serialize())
837
+ self.assertEqual(expect, result)
799
838
 
800
839
  def test_pow(self):
801
840
  expect = make_expression_graph({
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env python3
2
2
  """Tests for the image_converter module."""
3
3
 
4
- from typing import Optional
5
-
6
4
  from absl.testing import parameterized
7
5
  import numpy
8
6
 
@@ -20,7 +18,7 @@ class ImageConverterTest(parameterized.TestCase):
20
18
  def test_from_file_format(
21
19
  self,
22
20
  data_format: str,
23
- expected: Optional[type[image_converter.ImageConverter]],
21
+ expected: type[image_converter.ImageConverter] | None,
24
22
  ) -> None:
25
23
  """Verifies `from_file_format` returns the correct converter class."""
26
24
  if expected is None:
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/env python3
2
2
  """Test for the ee.serializer module."""
3
3
 
4
+ from collections.abc import Callable
4
5
  import datetime
5
6
  import json
6
- from typing import Any, Callable, Union
7
+ from typing import Any
7
8
 
8
9
  import unittest
9
10
  import ee
@@ -11,7 +12,7 @@ from ee import apitestcase
11
12
  from ee import serializer
12
13
 
13
14
 
14
- def _max_depth(x: Union[dict[str, Any], list[Any], str]) -> int:
15
+ def _max_depth(x: dict[str, Any] | list[Any] | str) -> int:
15
16
  """Computes the maximum nesting level of some dict, list, or str."""
16
17
  if isinstance(x, dict):
17
18
  return 1 + max(_max_depth(v) for v in x.values())
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python3
2
2
  """Tests for the table_converter module."""
3
3
 
4
- from typing import Any, Optional
4
+ from typing import Any
5
5
 
6
6
  from absl.testing import parameterized
7
7
  import geopandas
@@ -28,7 +28,7 @@ class TableConverterTest(parameterized.TestCase):
28
28
  def test_from_file_format(
29
29
  self,
30
30
  data_format: str,
31
- expected: Optional[type[table_converter.TableConverter]],
31
+ expected: type[table_converter.TableConverter] | None,
32
32
  ) -> None:
33
33
  """Verifies `from_file_format` returns the correct converter class."""
34
34
  if expected is None: