Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
]
```
"""
if columns is None:
columns = DEFAULT_COLUMNS
logger.debug("Converting each VesselMovement to a flat dictionary")
flatten = functools.partial(
convert_vessel_movement_to_flat_dict, cols=columns
)
with Pool(os.cpu_count()) as pool:
records = pool.map(flatten, super().to_list())
return create_dataframe(
columns=columns,
default_columns=DEFAULT_COLUMNS,
data=records,
logger_description="VesselMovements",
)
def to_df(self, columns=None) -> pd.DataFrame:
"""Represents the timeseries as a dataframe.
Returns a `pd.DataFrame`, of time series items with columns:
key: The time series key
value: The value of the time series for a given key
count: The number of records contributing to this time series record.
# Example:
If we're aggregating Crude exports in tonnes by day, then the `key` column holds the date,
the `value` column holds the Crude exports on that day, and the `count` column holds
the number of cargo movements contributing towards this day's tonnage.
"""
return create_dataframe(
columns=columns,
default_columns=DEFAULT_COLUMNS,
data=super().to_list(),
logger_description="TimeSeries",
)
def to_df(self, columns=None) -> pd.DataFrame:
"""
Represent corporations as a `pd.DataFrame`.
# Arguments
columns: The corporation features we want in the dataframe. Enter `columns='all'` to include all features.
Defaults to `columns = ['id', 'name', 'corporate_entity_type']`.
# Returns
`pd.DataFrame` of corporations.
"""
return create_dataframe(
columns=columns,
default_columns=DEFAULT_COLUMNS,
data=super().to_list(),
logger_description="Corporations",
)
def to_df(self, columns=None) -> pd.DataFrame:
"""
Represent vessels as a `pd.DataFrame`.
# Arguments
columns: The vessel features we want in the dataframe. Enter `columns='all'` to include all features.
Defaults to `columns = ['id', 'name', 'imo', 'vessel_class']`.
# Returns
`pd.DataFrame` of vessels.
"""
return create_dataframe(
columns=columns,
default_columns=DEFAULT_COLUMNS,
data=super().to_list(),
logger_description="Vessels",
)
]
```
"""
if columns is None:
columns = DEFAULT_COLUMNS
flatten = functools.partial(
convert_cargo_movement_to_flat_dict, cols=columns
)
logger.debug("Converting each CargoMovement to a flat dictionary")
with Pool(os.cpu_count()) as pool:
records = pool.map(flatten, super().to_list())
return create_dataframe(
columns=columns,
default_columns=DEFAULT_COLUMNS,
data=records,
logger_description="CargoMovements",
)
def to_df(self, columns=None) -> pd.DataFrame:
"""
Represent attributes as a `pd.DataFrame`.
# Arguments
columns: The attributes features we want in the dataframe. Enter `columns='all'` to include all features.
Defaults to `columns = ['id', 'name', 'type']`.
# Returns
`pd.DataFrame` of attributes.
"""
return create_dataframe(
columns=columns,
default_columns=DEFAULT_COLUMNS,
data=super().to_list(),
logger_description="Attributes",
)
def to_df(self, columns=None) -> pd.DataFrame:
"""
Represent products as a `pd.DataFrame`.
# Arguments
columns: The product features we want in the dataframe. Enter `columns='all'` to include all features.
Defaults to `columns = ['id', 'name', 'layer.0', 'parent.0.name']`.
# Returns
`pd.DataFrame` of products.
"""
flattened_dicts = [flatten_dictionary(p) for p in super().to_list()]
return create_dataframe(
columns=columns,
default_columns=DEFAULT_COLUMNS,
data=flattened_dicts,
logger_description="Products",
)