python - Rename new column function testing
问题描述
I am testing the below "if mode" that someone has written by input values to see if function is working as expected
def modify_col(self, tbl, new_col, mode, left, right):
if mode == 'rename_column':
self.df[tbl] = self.df[tbl].withColumn(new_col, F.col(left))
I wrote the below unit test code and my issue is the function is wrong or am I inputing wrong values or the logic I put in is wrong: below is the unit testing I ran and its failing
def test_modify_rename_column(self):
"""
Test make_new_col function.
"""
test_data= [
{'A': 12,'B': 11},
{'A': 12,'B': 13}
]
expected = [
{'A': 12, 'B': 11,'rename_column_test':1},
{'A': 12, 'B': 13,'rename_column_test':1}
]
self.lib.df['test_data'] = self.spark.createDataFrame(test_data).alias('test_data')
self.lib.modify_col(
tbl = 'test_data',
new_col = 'rename_column_test',
mode = 'rename_column',
left = 'A',
right = 'B'
)
actual = (
self.lib.df['test_data']
.toPandas()
.sort_values(['A'])
.to_dict(orient='records')
)
assert expected == actual
I am getting an error:
> AssertionError:
AssertionError Traceback (most recent call last)
in engine
----> 1 t.test_modify_rename_column()
<ipython-input-1-35d82a35840a> in test_modify_rename_column(self)
893 .to_dict(orient='records')
894 )
--> 895 assert expected == actual
896
897
AssertionError:
Any help can provide to fix this issue would be really appreciated. Thanking you in advance
解决方案
推荐阅读
- python - 为什么我们在keras模型中使用smooth变量来计算dice_coef或IoU?
- oracle - 在客户端选择时,Oracle apex-更新服务器上的项目值
- reactjs - 用“功能组件”实现事件监听和生命周期
- excel - 根据数字选择 Excel 工作表
- swift - 对 Swift 中的向下转换值感到困惑
- java - 如何确定我的 OpenJDK 库中使用的 xerces 版本?
- google-cloud-platform - 如何使用 webhook 从完整请求对话框流中读取参数?
- flutter - 使用颤振提供程序小部件时出现以下错误
- c++ - 继承类和 CUDA 的问题
- r - ggplot中具有多个变量的时间序列