diff --git a/striplog/component.py b/striplog/component.py index 2e31b15..c796513 100644 --- a/striplog/component.py +++ b/striplog/component.py @@ -37,9 +37,7 @@ def __init__(self, properties=None): # Cope with a boolean... setattr(self, k, v) else: - try: # To treat as number... - setattr(self, k, float(v)) - except ValueError: # Just add it. + try: setattr(self, k, v) except TypeError: # It's probably None. continue @@ -106,8 +104,8 @@ def __eq__(self, other): s = {k.lower(): v.lower() for k, v in ds if v} o = {k.lower(): v.lower() for k, v in do if v} except (AttributeError, ValueError): # Dealing with numbers. - s = {k.lower(): v for k, v in ds if isinstance(v, strobj) or isinstance(v, bool)} - o = {k.lower(): v for k, v in do if isinstance(v, strobj) or isinstance(v, bool)} + s = {k.lower(): v for k, v in ds if isinstance(v, strobj) or isinstance(v, bool) or isinstance(v, int)} + o = {k.lower(): v for k, v in do if isinstance(v, strobj) or isinstance(v, bool) or isinstance(v, int)} # Compare. if s == o: diff --git a/striplog/striplog.py b/striplog/striplog.py index f77f189..67bf55b 100644 --- a/striplog/striplog.py +++ b/striplog/striplog.py @@ -662,6 +662,62 @@ def from_csv(cls, filename=None, f.close() + remap = remap or {} + for k, v in remap.items(): + reorg[v] = reorg.pop(k) + + data = cls._clean_longitudinal_data(reorg, null=null) + + list_of_Intervals = cls._build_list_of_Intervals(data, + points=points, + lexicon=lexicon, + include=include, + exclude=exclude, + ignore=ignore, + stop=stop) + + return cls(list_of_Intervals, source=source) + + @classmethod + def from_dict_advanced(cls, dict, + lexicon=None, + points=False, + include=None, + exclude=None, + remap=None, + function=None, + null=None, + ignore=None, + source=None, + stop=None, + ): + """ + Load from a dictionary reusing `from_csv` post processing. + + Args + dict (dict): python dict containing the data. + lexicon (Lexicon): The lexicon to use, optional. Only needed if \ + parsing descriptions (e.g. cuttings). + points (bool): Whether to make a point dataset (as opposed to \ + ordinary intervals with top and base. Default is False. + include: Default is None. + exclude: Default is None. + remap: Default is None. + function: Default is None. + null: Default is None. + ignore: Default is None. + source: Default is None. + stop: Default is None. + fieldnames: Default is None. + + Returns + Striplog. A new instance. + """ + + # Reorganize the data to make fixing it easier. + reorg = dict + + remap = remap or {} for k, v in remap.items(): reorg[v] = reorg.pop(k) @@ -1095,7 +1151,7 @@ def copy(self): order=self.order, source=self.source) - + @@ -1230,7 +1286,7 @@ def to_log(self, you are asking for. It's up to you to make sure the function does what you want. bins (bool): Whether to return the index of the items from the - lookup table. If False, then the item itself will be returned. + lookup table. If False, then the item itself will be returned. dtype (str): The NumPy dtype string for the output log. table (list): Provide a look-up table of values if you want. If you don't, then it will be constructed from the data. @@ -2623,7 +2679,7 @@ def from_macrostrat(cls, lng, lat, buffer_size=0.2): This is simply a helper function to make things easier, but it works because we know what our data looks like in advance. - Note: In order to plot this, you will need to add space for text and + Note: In order to plot this, you will need to add space for text and other decoration. This simply gives a Striplog back which _can_ be plotted. @@ -2640,8 +2696,8 @@ def from_macrostrat(cls, lng, lat, buffer_size=0.2): lat = 44.4454632 buffer_size = 0.3 striplog.striplog.from_macrostrat(lng, lat, buffer_size) - {'top': Position({'middle': 358.9, 'units': 'm'}), - 'base': Position({'middle': 419.2, 'units': 'm'}), + {'top': Position({'middle': 358.9, 'units': 'm'}), + 'base': Position({'middle': 419.2, 'units': 'm'}), 'description': '', 'data': {}, 'components': [Component({ 'map_id': 948660.0, 'scale': 'small', 'source_id': 7.0, 'name': 'Devonian plutonic: undivided granitic rocks', @@ -2665,7 +2721,7 @@ def from_macrostrat(cls, lng, lat, buffer_size=0.2): 't_int': 112.0, 'b_int': 122.0, 'color': '#409963', 'source': 'MacroStrat.org (CC-BY)})]} """ - # Get the + # Get the features = utils.geology_from_macrostrat(lng=lng, lat=lat, buffer_size=buffer_size) diff --git a/tests/test_component.py b/tests/test_component.py index 18cfcf4..91e8350 100644 --- a/tests/test_component.py +++ b/tests/test_component.py @@ -90,3 +90,8 @@ def test_from_text(): assert rock3 == rock4 rock5 = Component.from_text(s, lexicon, required='not there') assert not rock5 # Should be None + +def test_integer_comparison(): + formations = range(1, 3) + table = [Component({'lith': l}) for l in formations] + assert (table[0] == table[1]) is False