diff --git a/README.md b/README.md index 7c3cabb..9a01422 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This is a demo repository to showcase the ability to diff different types of fil ## Example Files -- `code-example.py`: Contains basic math functions like add, substract, multiply, divide, and modulus. +- `code-example.py`: Contains basic math functions like add, subtract, multiply, divide, and modulus. - `pandas-example.ipynb`: Shows how to do operations on pandas DataFrames and Series, and includes some random data. ## How to Use @@ -23,8 +23,7 @@ Just browse the files and make some changes. You can try to add new functions, f ## Known Issues -- Sometimes the notebook outputs are not shown in the diff. -- There may be some spelling errors in the code and markdowns. +- There may be some spelling errors in the code and markdown. - The code is not tested for all edge cases. Enjoy exploring the repo! diff --git a/code-example.py b/code-example.py index 04c4594..e4b3601 100644 --- a/code-example.py +++ b/code-example.py @@ -14,7 +14,11 @@ def divide(a, b): if b != 0: return a / b else: - return None + raise ValueError("Division by zero is not allowed") + + +def modulus(a, b): + return a % b def main(): @@ -22,6 +26,7 @@ def main(): print("Subtraction:", subtract(10, 5)) print("Multiplication:", multiply(10, 5)) print("Division:", divide(10, 5)) + print("Modulus:", modulus(10, 5)) if __name__ == "__main__": diff --git a/pandas-example.ipynb b/pandas-example.ipynb index 04ea17f..57878b8 100644 --- a/pandas-example.ipynb +++ b/pandas-example.ipynb @@ -11,7 +11,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Copied from [https://github.com/jakevdp/PythonDataScienceHandbook](https://github.com/jakevdp/PythonDataScienceHandbook)" + "Copied from [https://github.com/jakevdp/PythonDataScienceHandbook](https://github.com/jakevdp/PythonDataScienceHandbook) with modifications to demonstrate notebook diffing." ] }, { @@ -19,16 +19,16 @@ "metadata": {}, "source": [ "One of the essential pieces of NumPy is the ability to perform quick element-wise operations, both with basic arithmetic (addition, subtraction, multiplication, etc.) and with more sophisticated operations (trigonometric functions, exponential and logarithmic functions, etc.).\n", - "Pandas inherits much of this functionality from NumPy, and the ufuncs that we introduced in [Computation on NumPy Arrays: Universal Functions](02.03-Computation-on-arrays-ufuncs.ipynb) are key to this.\n", + "Pandas inherits much of this functionality from NumPy, and the ufuncs that we introduced in [Computation on NumPy Arrays: Universal Functions](https://gitnotebooks.com/blog) are key to this.\n", "\n", "Pandas includes a couple useful twists, however: for unary operations like negation and trigonometric functions, these ufuncs will *preserve index and column labels* in the output, and for binary operations such as addition and multiplication, Pandas will automatically *align indices* when passing the objects to the ufunc.\n", "This means that keeping the context of data and combining data from different sources–both potentially error-prone tasks with raw NumPy arrays–become essentially foolproof ones with Pandas.\n", - "We will additionally see that there are well-defined operations between one-dimensional ``Series`` structures and two-dimensional ``DataFrame`` structures." + "We will additionally see that there are well-defined operations between one-dimensional Series structures and two-dimensional DataFrame structures." ] }, { "cell_type": "code", - "execution_count": 121, + "execution_count": 26, "metadata": { "collapsed": true }, @@ -48,7 +48,7 @@ }, { "cell_type": "code", - "execution_count": 122, + "execution_count": 27, "metadata": { "collapsed": false }, @@ -68,7 +68,7 @@ }, { "cell_type": "code", - "execution_count": 123, + "execution_count": 28, "metadata": { "collapsed": false }, @@ -77,26 +77,26 @@ "data": { "text/plain": [ "0 2.0\n", - "1 5.0\n", - "2 9.0\n", - "3 5.0\n", + "1 3.0\n", + "2 3.0\n", + "3 -5.0\n", "dtype: float64" ] }, - "execution_count": 123, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "A.add(B, fill_value=0)" + "A.subtract(B, fill_value=0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Notice that indices are aligned correctly irrespective of their order in the two objects, and indices in the result are sorted.\n", + "Observe that the indices align accurately regardless of their sequence in the two objects, and the result's indices are organized in ascending order.\n", "As was the case with ``Series``, we can use the associated object's arithmetic method and pass any desired ``fill_value`` to be used in place of missing entries.\n", "Here we'll fill with the mean of all values in ``A`` (computed by first stacking the rows of ``A``):" ] @@ -144,40 +144,36 @@ "