Skip to content

Commit 1b025fd

Browse files
committed
rename to select + use class there.
1 parent f27f1d6 commit 1b025fd

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

climada/entity/exposures/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def append(self, exposures):
261261
self.id[dup_id] = new_id
262262
new_id += 1
263263

264-
def select_region(self, reg_id):
264+
def select(self, reg_id):
265265
"""Return reference exposure of given region.
266266
267267
Parameters:
@@ -277,7 +277,7 @@ def select_region(self, reg_id):
277277
LOGGER.info('No exposure with region id %s.', reg_id)
278278
return None
279279

280-
sel_exp = Exposures()
280+
sel_exp = self.__class__()
281281
sel_exp.tag.file_name = self.tag.file_name
282282
sel_exp.tag.description = 'Region ' + str(reg_id)
283283
sel_exp.ref_year = self.ref_year

climada/entity/exposures/black_marble.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def set_region(self, centroids,
117117
# TODO: accept input centroids as well
118118
raise NotImplementedError
119119

120-
def select_region(self, reg_id):
120+
def select(self, reg_id):
121121
""" Select exposures with input region.
122122
123123
Parameters:
@@ -128,10 +128,10 @@ def select_region(self, reg_id):
128128
Exposures
129129
"""
130130
if isinstance(reg_id, int):
131-
return Exposures.select_region(self, reg_id)
131+
return Exposures.select(self, reg_id)
132132

133133
try:
134-
return Exposures.select_region(self, \
134+
return Exposures.select(self, \
135135
int(iso_cntry.get(reg_id).numeric))
136136
except KeyError:
137137
LOGGER.info('No country %s found.', reg_id)

climada/entity/exposures/test/test_base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,12 @@ def test_check_wrongId_fail(self):
347347
self.assertIn('There are exposures with the same identifier.',
348348
cm.output[0])
349349

350-
class TestSelectRegion(unittest.TestCase):
350+
class TestSelect(unittest.TestCase):
351351
"""Test select_region from the Exposures class"""
352352
def test_sel_reg_pass(self):
353353
"""Select region"""
354354
expo = good_exposures()
355-
sel_expo = expo.select_region(1)
355+
sel_expo = expo.select(1)
356356

357357
self.assertEqual(sel_expo.value.size, 1)
358358
self.assertEqual(sel_expo.value[0], 1)
@@ -372,11 +372,12 @@ def test_sel_reg_pass(self):
372372
self.assertEqual(sel_expo.coord.shape[0], 1)
373373
self.assertEqual(sel_expo.coord[0, 0], 1)
374374
self.assertEqual(sel_expo.coord[0, 1], 2)
375+
self.assertIsInstance(sel_expo, Exposures)
375376

376377
def test_sel_wrong_pass(self):
377378
"""Select non-existent region"""
378379
expo = good_exposures()
379-
sel_expo = expo.select_region(5)
380+
sel_expo = expo.select(5)
380381
self.assertEqual(sel_expo, None)
381382

382383
# Execute Tests
@@ -386,5 +387,5 @@ def test_sel_wrong_pass(self):
386387
TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestReadParallel))
387388
TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestConstructor))
388389
TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestRemove))
389-
TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestSelectRegion))
390+
TESTS.addTests(unittest.TestLoader().loadTestsFromTestCase(TestSelect))
390391
unittest.TextTestRunner(verbosity=2).run(TESTS)

climada/entity/exposures/test/test_black_marble.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,21 @@ def test_select_reg_pass(self):
8686
exp.region_id[:101] = exp.region_id[:101]*780
8787
exp.region_id[101:] = exp.region_id[101:]*894
8888

89-
sel_exp = exp.select_region('TTO')
89+
sel_exp = exp.select('TTO')
9090
self.assertEqual(sel_exp.value.size, 101)
91-
sel_exp = exp.select_region('Trinidad and Tobago')
91+
sel_exp = exp.select('Trinidad and Tobago')
9292
self.assertEqual(sel_exp.value.size, 101)
93-
sel_exp = exp.select_region('TT')
93+
sel_exp = exp.select('TT')
9494
self.assertEqual(sel_exp.value.size, 101)
95+
self.assertIsInstance(sel_exp, BlackMarble)
9596

96-
sel_exp = exp.select_region('ZMB')
97+
sel_exp = exp.select('ZMB')
9798
self.assertEqual(sel_exp.value.size, 99)
98-
sel_exp = exp.select_region('Zambia')
99+
sel_exp = exp.select('Zambia')
99100
self.assertEqual(sel_exp.value.size, 99)
100-
sel_exp = exp.select_region('ZM')
101+
sel_exp = exp.select('ZM')
101102
self.assertEqual(sel_exp.value.size, 99)
103+
self.assertIsInstance(sel_exp, BlackMarble)
102104

103105
def test_select_not_included_pass(self):
104106
"""Select country that is not contained."""
@@ -112,7 +114,7 @@ def test_select_not_included_pass(self):
112114
exp.region_id[:101] = exp.region_id[:101]*780
113115
exp.region_id[101:] = exp.region_id[101:]*894
114116

115-
sel_exp = exp.select_region('UGA')
117+
sel_exp = exp.select('UGA')
116118
self.assertEqual(sel_exp, None)
117119

118120
def test_select_wrong_fail(self):
@@ -127,7 +129,7 @@ def test_select_wrong_fail(self):
127129
exp.region_id[:101] = exp.region_id[:101]*780
128130
exp.region_id[101:] = exp.region_id[101:]*894
129131

130-
sel_exp = exp.select_region('TTU')
132+
sel_exp = exp.select('TTU')
131133
self.assertEqual(sel_exp, None)
132134

133135
class TestProvinces(unittest.TestCase):

0 commit comments

Comments
 (0)