--------------------------------------------------------------------------- ZeroDivisionError Traceback (most recent call last) Cell In[5], line 15 13 balance_sheet = companies.get_balance_sheet_statement() 14 cashflow_statement = companies.get_cash_flow_statement() ---> 15 ratios = companies.ratios.collect_profitability_ratios() 17 #income_df = pd.DataFrame(income_statement) 18 #income_df.to_csv('income_statement.csv', index=True) 19 (...) 23 #cashflow_df = pd.DataFrame(cashflow_statement) 24 #cashflow_df.to_csv('cashflow_statement.csv', index=True) 26 ratios_df = pd.DataFrame(ratios) File c:\Users\Peter\AppData\Local\Programs\Python\Python311\Lib\site-packages\financetoolkit\base\ratios_controller.py:160, in Ratios.collect_profitability_ratios(self) 157 if self._profitability_ratios.empty: 158 profitability_ratios: dict = {} --> 160 profitability_ratios["Gross Margin"] = self.get_gross_margin() 161 profitability_ratios["Operating Margin"] = self.get_operating_margin() 162 profitability_ratios["Net Profit Margin"] = self.get_net_profit_margin() File c:\Users\Peter\AppData\Local\Programs\Python\Python311\Lib\site-packages\financetoolkit\base\helpers.py:42, in handle_errors..wrapper(*args, **kwargs) 40 def wrapper(*args, **kwargs): 41 try: ---> 42 return func(*args, **kwargs) 43 except KeyError as e: 44 function_name = func.__name__ File c:\Users\Peter\AppData\Local\Programs\Python\Python311\Lib\site-packages\financetoolkit\base\ratios_controller.py:605, in Ratios.get_gross_margin(self) 599 @handle_errors 600 def get_gross_margin(self): 601 """ 602 Calculate the gross margin, a profitability ratio that measures the percentage of 603 revenue that exceeds the cost of goods sold. 604 """ --> 605 return profitability.get_gross_margin( 606 self._income_statement.loc[:, "Revenue", :], 607 self._income_statement.loc[:, "Cost of Goods Sold", :], 608 ) File c:\Users\Peter\AppData\Local\Programs\Python\Python311\Lib\site-packages\financetoolkit\ratios\profitability.py:21, in get_gross_margin(revenue, cost_of_goods_sold) 7 def get_gross_margin( 8 revenue: float | pd.Series, cost_of_goods_sold: float | pd.Series 9 ) -> float | pd.Series: 10 """ 11 Calculate the gross margin, a profitability ratio that measures the percentage of 12 revenue that exceeds the cost of goods sold. (...) 19 float | pd.Series: The gross margin percentage value. 20 """ ---> 21 return (revenue - cost_of_goods_sold) / revenue File c:\Users\Peter\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\ops\common.py:81, in _unpack_zerodim_and_defer..new_method(self, other) 77 return NotImplemented 79 other = item_from_zerodim(other) ---> 81 return method(self, other) File c:\Users\Peter\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\arraylike.py:210, in OpsMixin.__truediv__(self, other) 208 @unpack_zerodim_and_defer("__truediv__") 209 def __truediv__(self, other): --> 210 return self._arith_method(other, operator.truediv) File c:\Users\Peter\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\frame.py:7457, in DataFrame._arith_method(self, other, op) 7453 other = ops.maybe_prepare_scalar_for_op(other, (self.shape[axis],)) 7455 self, other = ops.align_method_FRAME(self, other, axis, flex=True, level=None) -> 7457 new_data = self._dispatch_frame_op(other, op, axis=axis) 7458 return self._construct_result(new_data) File c:\Users\Peter\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\frame.py:7496, in DataFrame._dispatch_frame_op(self, right, func, axis) 7490 # TODO: The previous assertion `assert right._indexed_same(self)` 7491 # fails in cases with empty columns reached via 7492 # _frame_arith_method_with_reindex 7493 7494 # TODO operate_blockwise expects a manager of the same type 7495 with np.errstate(all="ignore"): -> 7496 bm = self._mgr.operate_blockwise( 7497 # error: Argument 1 to "operate_blockwise" of "ArrayManager" has 7498 # incompatible type "Union[ArrayManager, BlockManager]"; expected 7499 # "ArrayManager" 7500 # error: Argument 1 to "operate_blockwise" of "BlockManager" has 7501 # incompatible type "Union[ArrayManager, BlockManager]"; expected 7502 # "BlockManager" 7503 right._mgr, # type: ignore[arg-type] 7504 array_op, 7505 ) 7506 return self._constructor(bm) 7508 elif isinstance(right, Series) and axis == 1: 7509 # axis=1 means we want to operate row-by-row File c:\Users\Peter\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\internals\managers.py:1545, in BlockManager.operate_blockwise(self, other, array_op) 1541 def operate_blockwise(self, other: BlockManager, array_op) -> BlockManager: 1542 """ 1543 Apply array_op blockwise with another (aligned) BlockManager. 1544 """ -> 1545 return operate_blockwise(self, other, array_op) File c:\Users\Peter\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\internals\ops.py:63, in operate_blockwise(left, right, array_op) 61 res_blks: list[Block] = [] 62 for lvals, rvals, locs, left_ea, right_ea, rblk in _iter_block_pairs(left, right): ---> 63 res_values = array_op(lvals, rvals) 64 if left_ea and not right_ea and hasattr(res_values, "reshape"): 65 res_values = res_values.reshape(1, -1) File c:\Users\Peter\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\ops\array_ops.py:232, in arithmetic_op(left, right, op) 228 _bool_arith_check(op, left, right) 230 # error: Argument 1 to "_na_arithmetic_op" has incompatible type 231 # "Union[ExtensionArray, ndarray[Any, Any]]"; expected "ndarray[Any, Any]" --> 232 res_values = _na_arithmetic_op(left, right, op) # type: ignore[arg-type] 234 return res_values File c:\Users\Peter\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\ops\array_ops.py:171, in _na_arithmetic_op(left, right, op, is_cmp) 168 func = partial(expressions.evaluate, op) 170 try: --> 171 result = func(left, right) 172 except TypeError: 173 if not is_cmp and (is_object_dtype(left.dtype) or is_object_dtype(right)): 174 # For object dtype, fallback to a masked operation (only operating 175 # on the non-missing values) 176 # Don't do this for comparisons, as that will handle complex numbers 177 # incorrectly, see GH#32047 File c:\Users\Peter\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\computation\expressions.py:239, in evaluate(op, a, b, use_numexpr) 236 if op_str is not None: 237 if use_numexpr: 238 # error: "None" not callable --> 239 return _evaluate(op, op_str, a, b) # type: ignore[misc] 240 return _evaluate_standard(op, op_str, a, b) File c:\Users\Peter\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\computation\expressions.py:70, in _evaluate_standard(op, op_str, a, b) 68 if _TEST_MODE: 69 _store_test_result(False) ---> 70 return op(a, b) ZeroDivisionError: division by zero