Converters¶
Summary¶
|
Convert coordinate pairs in response items from strings to floats, if valid |
|
Convert locations for both standard and community-contributed places to floats |
|
Replace all date/time info with datetime objects, where possible |
|
Convert list parameters into an API-compatible (comma-delimited) string |
|
Replace generic created/updated info that's returned by multiple endpoints. |
|
Convert a response containing time series data into a single |
|
Convert a date, datetime, or timestamps to a string in ISO 8601 format. |
|
Convert a coordinate pair as a dict, list, or string into a pair of floats, if valid |
|
Convert a coordinate pair dict within a response to floats, if valid |
|
Convert a coordinate pairs in a response item from strings to floats, if valid |
|
Convert an observation timestamp + timezone info to a datetime. |
|
Replace observation date/time info with datetime objects |
|
Use timezone offset info to replace a datetime's tzinfo |
|
Given a file path or URL, load data into a file-like object |
|
Convert an object, response, or (optionally) comma-separated string into a list |
|
Simplify a 'dimensions' dict into a |
|
Convert a file size in bytes into a human-readable format |
|
Format a Creative Commons license code |
|
Convert a timezone offset string to a tzoffset object, accounting for some common variations in format |
|
Split a pipe-(or other token)-delimited string |
|
Remove any dict items with empty or |
|
Parse a timestamp string into a datetime, if valid; return |
|
Convert a value to a float, if valid; return |
|
Convert a pair of coordinat values to floats, if both are valid; return |
|
Convert a value to a int, if valid; return |
|
Convert a value to either an int or a float, if valid; return |
Module Contents¶
Type conversion utilities
- pyinaturalist.converters.convert_all_coordinates(results)¶
Convert coordinate pairs in response items from strings to floats, if valid
- pyinaturalist.converters.convert_all_place_coordinates(response)¶
Convert locations for both standard and community-contributed places to floats
- pyinaturalist.converters.convert_all_timestamps(results)¶
Replace all date/time info with datetime objects, where possible
- pyinaturalist.converters.convert_csv_list(obj)¶
Convert list parameters into an API-compatible (comma-delimited) string
- Return type
- pyinaturalist.converters.convert_generic_timestamps(result)¶
Replace generic created/updated info that’s returned by multiple endpoints. Note: Compared to observation timestamps, these are generally more reliable. These seem to be consistently in ISO 8601 format.
- pyinaturalist.converters.convert_histogram(response)¶
Convert a response containing time series data into a single
{date: value}
dict
- pyinaturalist.converters.convert_isoformat(value)¶
Convert a date, datetime, or timestamps to a string in ISO 8601 format. If it’s a datetime and doesn’t already have tzinfo, set it to the system’s local timezone.
- Raises
dateutil.parser._parser.ParserError –
- Return type
- pyinaturalist.converters.convert_lat_long(obj)¶
Convert a coordinate pair as a dict, list, or string into a pair of floats, if valid
- pyinaturalist.converters.convert_lat_long_dict(result)¶
Convert a coordinate pair dict within a response to floats, if valid
- pyinaturalist.converters.convert_lat_long_list(result)¶
Convert a coordinate pairs in a response item from strings to floats, if valid
- pyinaturalist.converters.convert_observation_timestamp(timestamp, tz_offset=None, tz_name=None, ignoretz=False)¶
Convert an observation timestamp + timezone info to a datetime. This is needed because observed_on and created_at can be in in inconsistent (user-submitted?) formats.
- pyinaturalist.converters.convert_observation_timestamps(result)¶
Replace observation date/time info with datetime objects
- pyinaturalist.converters.convert_offset(datetime_obj, tz_offset=None, tz_name=None)¶
Use timezone offset info to replace a datetime’s tzinfo
- pyinaturalist.converters.ensure_file_obj(value, session=None)¶
Given a file path or URL, load data into a file-like object
- Return type
- pyinaturalist.converters.ensure_list(value, convert_csv=False, delimiter=',')¶
Convert an object, response, or (optionally) comma-separated string into a list
- Return type
- pyinaturalist.converters.format_dimensions(dimensions)¶
Simplify a ‘dimensions’ dict into a
(width, height)
tuple
- pyinaturalist.converters.format_file_size(n_bytes)¶
Convert a file size in bytes into a human-readable format
- Return type
- pyinaturalist.converters.format_license(value)¶
Format a Creative Commons license code
- pyinaturalist.converters.parse_offset(tz_offset, tz_name=None)¶
Convert a timezone offset string to a tzoffset object, accounting for some common variations in format
Examples
>>> parse_offset('GMT-08:00', 'PST') tzoffset('PST', -28800) >>> parse_offset('-06:00') tzoffset(None, -21600) >>> parse_offset('+05:30') tzoffset(None, 19800) >>> parse_offset('0530') tzoffset(None, 19800)
- Return type
tzoffset
- pyinaturalist.converters.safe_split(value, delimiter='|')¶
Split a pipe-(or other token)-delimited string
- pyinaturalist.converters.strip_empty_values(values)¶
Remove any dict items with empty or
None
values.- Return type
- pyinaturalist.converters.try_datetime(timestamp, **kwargs)¶
Parse a timestamp string into a datetime, if valid; return
None
otherwise
- pyinaturalist.converters.try_float(value)¶
Convert a value to a float, if valid; return
None
otherwise
- pyinaturalist.converters.try_float_pair(*values)¶
Convert a pair of coordinat values to floats, if both are valid; return
None
otherwise
- pyinaturalist.converters.try_int(value)¶
Convert a value to a int, if valid; return
None
otherwise