Automated testing by pytest The most hard part in testing is to write test cases, which is time-consuming and error-prone. Fortunately, besides Python built-in modules such as doctest, unittest, there are quite a few third-party packages that could help with automated testing. My favorite one is pytest, which enjoys proven record and syntax sugar. Step 1: test-driven developmentFor example, there is a coding challenge on Leetcode: Find Minimum in Rotated Sorted Array Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the ...
Steps to deploy Flask's minitwit on Google App Enginee Flask is a light-weight web framework for Python, which is well documented and clearly written. Its Github depository provides a few examples, which includes minitwit. The minittwit website enjoys a few basic features of social network such as following, login/logout. The demo site on GAE is http://minitwit-123.appspot.com. The Github repo is https://github.com/dapangmao/minitwit.Google App Engine or GAE is a major public clouder service besides Amazon EC2. Among the four languages(Java/Python/Go/PHP) it supports, GAE is friendly to Python users, possibly because Guido van Rossum worked there and personally created Python datastore interface. As for me, it is a good choice for a ...
Translate SAS's sas7bdat format to SQLite and Pandas Thanks Jared Hobbs’ sas7bdat package, Python can read SAS’s data sets quickly and precisely. And it will be great to have a few extension functions to enhance this package with SQLite and Pandas. The good things to transfer SAS libraries to SQLite: Size reduction:SAS’s sas7bdat format is verbose. So far successfully loaded 40GB SAS data to SQLite with 85% reduction of disk usage.Save the cost to buy SAS/ACCESSSAS/ACCESS costs around $8,000 a year for a server, while SQLite is accessible for most common softwares.The good things to transfer SAS data set to Pandas: Pandas’ powerful Excel interface:Write very large Excel ...
One example of test-driven development in Python Function or method is the most basic unit in Python programming. Test-driven development is a key for a developer to assure the code quality of those units. In his book, Harry Percival illustrated a few great examples about how to use TDD with Python and Django. It seems that for web development, TDD including unit testing and integration testing is the cornerstone for every success. For data analysis, coding mostly relies on built-in packages instead large framework like Django, which makes TDD easier. In my opnion, TDD in data analysis could have three steps. Step 1: requirement analysis Before writing ...
Sorting in Python #-------------------------------------------------------------------------------# Name: Methods of sorting# Purpose: implements the sortings mentioned by Robert Sedgewick and# Kevin Wayne, Algorithms 4ed##-------------------------------------------------------------------------------def selection_sort(a): for i in range(len(a)): min = i for j in range(i+1, len(a)): if a[j] < a[min]: min = j a[i], a[min] = a[min], a[i]def insertion_sort(a): for i in range(len(a)): j = i while j > 0: if a[j] < a[j-1]: a[j], a[j-1] = a[j-1], a[j] j -= 1def shell_sort(a): h = 1 while h <= len(a)/3: h = 3*h+ 1 # in the test use 4 as increment sequence while h >= 1: for i in range(len(a)): j = i while ...