Skip to content

Commit 3f3b93f

Browse files
author
Reijonen Pekka
committed
Experimenting with libraries and unittests
1 parent 0c19dce commit 3f3b93f

5 files changed

Lines changed: 48 additions & 1 deletion

File tree

dataSelection/selectingMain.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def selectionMain(row):
2+
# this should be used to remove lines from data frame, so should return true or false
3+
return "foo"

dataTransforming/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'''
2+
This is a package called dataTransforming (a folder name)
3+
Instructions: to this file import source code files (modules) one by one.
4+
When using functions do not mention source code files (modules), only functions inside those source code files.
5+
Example on how to import function from this package
6+
from dataTransforming import transformationForData
7+
'''
8+
9+
from .transformingMain import *
10+
11+
12+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def transformationForData(row):
2+
# Should return transformed data, this one works line by line modifying data.
3+
transformedData="something"
4+
return transformedData

pipeLine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def dataHandlingMain(): # record : [2, 3, 1, "name"]
3030
modifiedDataSet = list(map((mapHandlerFunction(recordWhatIsNext)), dataset))
3131

3232
# function to be used inside map to handle data record
33-
def mapHandlerFunction(record):
33+
#def mapHandlerFunction(record):
3434
# here we need to know columns, meaning fields in the record
3535
# record[0]
3636

tests.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
# possible solution maybe here https://docs.python.org/3/library/unittest.mock.html#where-to-patch
2323
from example_pkg import foo_func
2424
from example_pkg import bar_func
25+
from dataTransforming import transformationForData
2526

27+
from functools import reduce
28+
import pandas as pd
29+
import numpy as np
2630
# import pipeLine
2731

2832
url = 'http://api.worldbank.org/v2/country/all/indicator/SP.POP.TOTL?format=json'
@@ -74,6 +78,30 @@ def test_playdata(self):
7478
df = pd.DataFrame({'c1': [10, 11, 12], 'c2': [100, 110, 120]})
7579
for index, row in df.iterrows():
7680
print(row['c1'], row['c2'])
81+
df.applymap
82+
83+
def test_framingApply(self):
84+
#https://stackoverflow.com/questions/16476924/how-to-iterate-over-rows-in-a-dataframe-in-pandas first version
85+
#
86+
df = pd.DataFrame({'c1': [10, 11, 12], 'c2': [100, 110, 120]})
87+
for index, row in df.iterrows():
88+
print(row['c1'], row['c2'])
89+
90+
df.apply(transformationForData, axis=0, raw=False, result_type=None, args=())
91+
#DataFrame.apply(func, axis=0, raw=False, result_type=None, args=(), **kwds)
92+
#transformingMain("testing")
93+
bar_func()
94+
95+
def test_sanity1(self):
96+
result = bar_func()
97+
result = transformationForData("testing")
98+
self.assertEqual(result,"testausta")
99+
100+
def test_sanity2(self):
101+
df = pd.DataFrame([[4, 9]] * 3, columns=['A', 'B'])
102+
print(df.apply(np.sqrt))
103+
print(df)
104+
77105

78106
if __name__ == '__main__':
79107
unittest.main()

0 commit comments

Comments
 (0)