-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create utilities module which is neccessary to fix #104 #115
Open
rluedde
wants to merge
11
commits into
cenpy-devs:master
Choose a base branch
from
rluedde:numeric_cols_104
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+237
−136
Open
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1699383
Create utilities module
rluedde 1808453
Fix _ACS_MISSING location
rluedde bc28c5a
Try to convert all data columns to ints
rluedde 74b449c
Coerce casts what it can and not all-or-none
1f2640b
Implement replace_missing recursively
rluedde 1d35e12
Fix imports of utilities functions
rluedde ad58c75
Fix name duplication
rluedde 403e595
Fix uppercase/lowercase apply_func bug
rluedde 3489b78
Merge branch 'numeric_cols_104' of https://github.com/rluedde/cenpy i…
rluedde ac0f845
Keep utilities functions private
rluedde dcbfb8a
Call utilities correctly
rluedde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import unittest | ||
import pandas | ||
import numpy | ||
from cenpy.utilities import _coerce as coerce | ||
from cenpy.utilities import _replace_missing as replace_missing | ||
|
||
class TestUtilities(unittest.TestCase): | ||
|
||
def test_coerce(self): | ||
# Make sure coerce works on Series and doesn't change them | ||
ser_orig = pandas.Series([3,4,5]) | ||
ser_floats = coerce(ser_orig, cast_to = numpy.float64) | ||
self.assertFalse(ser_orig.equals(ser_floats)) | ||
|
||
# Make sure coerce changes what columns it can and doesn't alter | ||
# original data | ||
df_orig = pandas.DataFrame({"ints": [1,2,3], | ||
"floats": [0.1, 3.79, 14.9], | ||
"strings": ["fst", "sec", "thd"]}) | ||
df_floats = coerce(df_orig, cast_to = numpy.float64) | ||
# Correct types of columns after coercion: | ||
float_dtypes = pandas.Series(["float64", "float64", "object"], | ||
index = ["ints", "floats", "strings"]) | ||
# Make sure that the coerced dtypes are as expected | ||
self.assertFalse(df_orig.equals(df_floats)) | ||
self.assertTrue(float_dtypes.equals(df_floats.dtypes)) | ||
|
||
# Cast castable columns into strings - | ||
# Confusingly enough, pandas calls them "objects" | ||
df_objects = coerce(df_orig, cast_to = str) | ||
object_dtypes = pandas.Series(["object", "object", "object"], | ||
index = ["ints", "floats", "strings"]) | ||
self.assertTrue(object_dtypes.equals(df_objects.dtypes)) | ||
|
||
# Make sure an error gets raised if a non-Series/DataFrame object is used | ||
arr = numpy.zeros((2,2)) | ||
self.assertRaises(TypeError, coerce, arr) | ||
|
||
|
||
def test_replace_missing(self): | ||
df_orig = pandas.DataFrame({"ints": [-888888888,2,3], | ||
"floats": [-555555555, 3.79, -333333333]}) | ||
df_replaced = replace_missing(df_orig) | ||
# Correct output after replacing missing values | ||
df_correct = pandas.DataFrame({"ints": [numpy.nan,2,3], | ||
"floats": [numpy.nan, 3.79, numpy.nan]}) | ||
self.assertTrue(df_replaced.equals(df_correct)) | ||
|
||
# Make sure an error is raised if non-Series/DataFrame types are used | ||
arr = numpy.zeros((2,2)) | ||
self.assertRaises(TypeError, replace_missing, arr) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are these private functions being made public here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They shouldn't be. I'll fix that in a few.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I addressed this in my most recent commit.