{"action":"created","comment":{"url":"https://api.github.com/repos/biota/sourcetracker2/pulls/comments/77842728","id":77842728,"diff_hunk":"@@ -9,80 +9,92 @@\n # ----------------------------------------------------------------------------\n from __future__ import division\n \n+import matplotlib\n+matplotlib.use('Agg')  # noqa: E402\n+\n import numpy as np\n from skbio.stats import subsample_counts\n import pandas as pd\n from functools import partial\n \n+import seaborn as sns\n+import matplotlib.pyplot as plt\n+\n \n-def check_and_correct_data(feature_table, apply_fractional_value_correction):\n-    '''Check and correct problems in the `feature_table`.\n+def validate_gibbs_input(sources, sinks=None):\n+    '''Validate `gibbs` inputs and coerce/round to type `np.int32`.\n+\n+    Summary\n+    -------\n+    Checks if data contains `nan` or `null` values, and returns data as\n+    type `np.int32`. If both `sources` and `sinks` are passed, columns must\n+    match exactly (including order).\n \n     Parameters\n     ----------\n-    feature_table : pd.DataFrame\n-        Feature table where rows are features and columns are samples.\n-    apply_fractional_value_correction : boolean\n-        Fractional counts cause errors in indexing. Uses np.ceil to remove\n-        them if True.\n+    sources : pd.DataFrame\n+        A dataframe containing count data. Must be castable to `np.int32`.\n+    sinks : optional, pd.DataFrame or None\n+        If not `None` a dataframe containing count data that is castable to\n+        `np.int32`.\n \n     Returns\n     -------\n-    feature_table : pd.DataFrame\n-        Corrected feature table if changes have been made or original table if\n-        no changes occurred. Will automatically be cast as dtype=np.int64\n+    pd.Dataframe(s)\n \n     Raises\n     ------\n     ValueError\n-        If data contains values that Gibb's sampling cannot handle.\n+        If `nan` or `null` values found in inputs.\n+    ValueError\n+        If any values are smaller than 0.\n+    ValueError\n+        If any columns of an input dataframe are non-numeric.\n+    ValueError\n+        If `sources` and `sinks` passed and columns are not identical.\n     '''\n-    if not np.isreal(feature_table.dtypes).all():\n-        raise TypeError('Feature table contains one or more columns which are '\n-                        'not numeric type. This is likely due to boolean, '\n-                        'string, or other data types being present. Data must '\n-                        'contain exclusively real-valued integers or floats.')\n-\n-    if np.isnan(feature_table.values).any():\n-        raise ValueError('One or more values in the feature table is a `nan` '\n-                         'or `null` value. Data must contain exclusively real-'\n-                         'valued integers or floats.')\n-\n-    if not (np.ceil(feature_table.values) == feature_table.values).all():\n-        if apply_fractional_value_correction is True:\n-            return pd.DataFrame(np.ceil(feature_table.values).astype(np.int64),\n-                                index=feature_table.index,\n-                                columns=feature_table.columns)\n-        else:\n-            raise ValueError('Non-integer data in the feature table is not '\n-                             'being corrected by `check_and_correct_data`. '\n-                             'Data leaving this function must be np.int64 '\n-                             'type. Either correct the table or pass the '\n-                             '`apply_fractional_value_correction` to '\n-                             '`check_and_correct_data`.')\n-    return feature_table.astype(np.int64)\n+    if sinks is not None:\n+        dfs = [sources, sinks]\n+    else:\n+        dfs = [sources]\n+\n+    for df in dfs:\n+        # Because of this bug (https://github.com/numpy/numpy/issues/6114)\n+        # we can't use e.g. np.isreal(df.dtypes).all(). Instead we use\n+        # applymap. Based on:\n+        # http://stackoverflow.com/questions/21771133/finding-non-numeric-rows-in-dataframe-in-pandas\n+        if not df.applymap(np.isreal).values.all():\n+            raise ValueError('A dataframe contains one or more values which '\n+                             'are not numeric. Data must be exclusively '\n+                             'positive integers.')\n+        if np.isnan(df.values).any():\n+            raise ValueError('A dataframe has `nan` or `null` values. Data '\n+                             'must be exclusively positive integers.')\n+        if (df.values < 0).any():\n+            raise ValueError('A dataframe has a negative count. Data '\n+                             'must be exclusively positive integers.')\n+\n+    if sinks is not None:\n+        if not (sinks.columns == sources.columns).all():\n+            raise ValueError('Dataframes do not contain identical (and '\n+                             'identically ordered) columns. Columns must '\n+                             'match exactly.')\n+        return sources.astype(np.int32), sinks.astype(np.int32)","path":"sourcetracker/_sourcetracker.py","position":109,"original_position":109,"commit_id":"c3c597086d78adb94b78d56aa71d82ece3688d68","original_commit_id":"c3c597086d78adb94b78d56aa71d82ece3688d68","user":{"login":"gregcaporaso","id":192372,"avatar_url":"https://avatars.githubusercontent.com/u/192372?v=3","gravatar_id":"","url":"https://api.github.com/users/gregcaporaso","html_url":"https://github.com/gregcaporaso","followers_url":"https://api.github.com/users/gregcaporaso/followers","following_url":"https://api.github.com/users/gregcaporaso/following{/other_user}","gists_url":"https://api.github.com/users/gregcaporaso/gists{/gist_id}","starred_url":"https://api.github.com/users/gregcaporaso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gregcaporaso/subscriptions","organizations_url":"https://api.github.com/users/gregcaporaso/orgs","repos_url":"https://api.github.com/users/gregcaporaso/repos","events_url":"https://api.github.com/users/gregcaporaso/events{/privacy}","received_events_url":"https://api.github.com/users/gregcaporaso/received_events","type":"User","site_admin":false},"body":"Could we do these type casts in place (but still return the relevant objects) for both ``return`` cases? I'm worried about this blowing up memory. ","created_at":"2016-09-07T15:13:43Z","updated_at":"2016-09-07T15:13:43Z","html_url":"https://github.com/biota/sourcetracker2/pull/71#discussion_r77842728","pull_request_url":"https://api.github.com/repos/biota/sourcetracker2/pulls/71","_links":{"self":{"href":"https://api.github.com/repos/biota/sourcetracker2/pulls/comments/77842728"},"html":{"href":"https://github.com/biota/sourcetracker2/pull/71#discussion_r77842728"},"pull_request":{"href":"https://api.github.com/repos/biota/sourcetracker2/pulls/71"}}},"pull_request":{"url":"https://api.github.com/repos/biota/sourcetracker2/pulls/71","id":84247258,"html_url":"https://github.com/biota/sourcetracker2/pull/71","diff_url":"https://github.com/biota/sourcetracker2/pull/71.diff","patch_url":"https://github.com/biota/sourcetracker2/pull/71.patch","issue_url":"https://api.github.com/repos/biota/sourcetracker2/issues/71","number":71,"state":"open","locked":false,"title":"Api","user":{"login":"wdwvt1","id":1048569,"avatar_url":"https://avatars.githubusercontent.com/u/1048569?v=3","gravatar_id":"","url":"https://api.github.com/users/wdwvt1","html_url":"https://github.com/wdwvt1","followers_url":"https://api.github.com/users/wdwvt1/followers","following_url":"https://api.github.com/users/wdwvt1/following{/other_user}","gists_url":"https://api.github.com/users/wdwvt1/gists{/gist_id}","starred_url":"https://api.github.com/users/wdwvt1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wdwvt1/subscriptions","organizations_url":"https://api.github.com/users/wdwvt1/orgs","repos_url":"https://api.github.com/users/wdwvt1/repos","events_url":"https://api.github.com/users/wdwvt1/events{/privacy}","received_events_url":"https://api.github.com/users/wdwvt1/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-09-07T07:06:51Z","updated_at":"2016-09-07T15:13:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a7165871123ae4a6bb9cf03b4fbf54a150a302b9","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/biota/sourcetracker2/pulls/71/commits","review_comments_url":"https://api.github.com/repos/biota/sourcetracker2/pulls/71/comments","review_comment_url":"https://api.github.com/repos/biota/sourcetracker2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/biota/sourcetracker2/issues/71/comments","statuses_url":"https://api.github.com/repos/biota/sourcetracker2/statuses/c3c597086d78adb94b78d56aa71d82ece3688d68","head":{"label":"wdwvt1:api","ref":"api","sha":"c3c597086d78adb94b78d56aa71d82ece3688d68","user":{"login":"wdwvt1","id":1048569,"avatar_url":"https://avatars.githubusercontent.com/u/1048569?v=3","gravatar_id":"","url":"https://api.github.com/users/wdwvt1","html_url":"https://github.com/wdwvt1","followers_url":"https://api.github.com/users/wdwvt1/followers","following_url":"https://api.github.com/users/wdwvt1/following{/other_user}","gists_url":"https://api.github.com/users/wdwvt1/gists{/gist_id}","starred_url":"https://api.github.com/users/wdwvt1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wdwvt1/subscriptions","organizations_url":"https://api.github.com/users/wdwvt1/orgs","repos_url":"https://api.github.com/users/wdwvt1/repos","events_url":"https://api.github.com/users/wdwvt1/events{/privacy}","received_events_url":"https://api.github.com/users/wdwvt1/received_events","type":"User","site_admin":false},"repo":{"id":63194292,"name":"sourcetracker2","full_name":"wdwvt1/sourcetracker2","owner":{"login":"wdwvt1","id":1048569,"avatar_url":"https://avatars.githubusercontent.com/u/1048569?v=3","gravatar_id":"","url":"https://api.github.com/users/wdwvt1","html_url":"https://github.com/wdwvt1","followers_url":"https://api.github.com/users/wdwvt1/followers","following_url":"https://api.github.com/users/wdwvt1/following{/other_user}","gists_url":"https://api.github.com/users/wdwvt1/gists{/gist_id}","starred_url":"https://api.github.com/users/wdwvt1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wdwvt1/subscriptions","organizations_url":"https://api.github.com/users/wdwvt1/orgs","repos_url":"https://api.github.com/users/wdwvt1/repos","events_url":"https://api.github.com/users/wdwvt1/events{/privacy}","received_events_url":"https://api.github.com/users/wdwvt1/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wdwvt1/sourcetracker2","description":"SourceTracker2","fork":true,"url":"https://api.github.com/repos/wdwvt1/sourcetracker2","forks_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/forks","keys_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/teams","hooks_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/hooks","issue_events_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/issues/events{/number}","events_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/events","assignees_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/assignees{/user}","branches_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/branches{/branch}","tags_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/tags","blobs_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/git/refs{/sha}","trees_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/statuses/{sha}","languages_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/languages","stargazers_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/stargazers","contributors_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/contributors","subscribers_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/subscribers","subscription_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/subscription","commits_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/commits{/sha}","git_commits_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/git/commits{/sha}","comments_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/comments{/number}","issue_comment_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/issues/comments{/number}","contents_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/contents/{+path}","compare_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/merges","archive_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/downloads","issues_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/issues{/number}","pulls_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/pulls{/number}","milestones_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/milestones{/number}","notifications_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/labels{/name}","releases_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/releases{/id}","deployments_url":"https://api.github.com/repos/wdwvt1/sourcetracker2/deployments","created_at":"2016-07-12T21:42:36Z","updated_at":"2016-07-12T21:42:38Z","pushed_at":"2016-09-07T08:45:51Z","git_url":"git://github.com/wdwvt1/sourcetracker2.git","ssh_url":"git@github.com:wdwvt1/sourcetracker2.git","clone_url":"https://github.com/wdwvt1/sourcetracker2.git","svn_url":"https://github.com/wdwvt1/sourcetracker2","homepage":"","size":230,"stargazers_count":0,"watchers_count":0,"language":"Jupyter Notebook","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"biota:master","ref":"master","sha":"7b0c89b6b099efc2baf0e1276cee9c9c795120fc","user":{"login":"biota","id":10524089,"avatar_url":"https://avatars.githubusercontent.com/u/10524089?v=3","gravatar_id":"","url":"https://api.github.com/users/biota","html_url":"https://github.com/biota","followers_url":"https://api.github.com/users/biota/followers","following_url":"https://api.github.com/users/biota/following{/other_user}","gists_url":"https://api.github.com/users/biota/gists{/gist_id}","starred_url":"https://api.github.com/users/biota/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biota/subscriptions","organizations_url":"https://api.github.com/users/biota/orgs","repos_url":"https://api.github.com/users/biota/repos","events_url":"https://api.github.com/users/biota/events{/privacy}","received_events_url":"https://api.github.com/users/biota/received_events","type":"Organization","site_admin":false},"repo":{"id":54203418,"name":"sourcetracker2","full_name":"biota/sourcetracker2","owner":{"login":"biota","id":10524089,"avatar_url":"https://avatars.githubusercontent.com/u/10524089?v=3","gravatar_id":"","url":"https://api.github.com/users/biota","html_url":"https://github.com/biota","followers_url":"https://api.github.com/users/biota/followers","following_url":"https://api.github.com/users/biota/following{/other_user}","gists_url":"https://api.github.com/users/biota/gists{/gist_id}","starred_url":"https://api.github.com/users/biota/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biota/subscriptions","organizations_url":"https://api.github.com/users/biota/orgs","repos_url":"https://api.github.com/users/biota/repos","events_url":"https://api.github.com/users/biota/events{/privacy}","received_events_url":"https://api.github.com/users/biota/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/biota/sourcetracker2","description":"SourceTracker2","fork":false,"url":"https://api.github.com/repos/biota/sourcetracker2","forks_url":"https://api.github.com/repos/biota/sourcetracker2/forks","keys_url":"https://api.github.com/repos/biota/sourcetracker2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/biota/sourcetracker2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/biota/sourcetracker2/teams","hooks_url":"https://api.github.com/repos/biota/sourcetracker2/hooks","issue_events_url":"https://api.github.com/repos/biota/sourcetracker2/issues/events{/number}","events_url":"https://api.github.com/repos/biota/sourcetracker2/events","assignees_url":"https://api.github.com/repos/biota/sourcetracker2/assignees{/user}","branches_url":"https://api.github.com/repos/biota/sourcetracker2/branches{/branch}","tags_url":"https://api.github.com/repos/biota/sourcetracker2/tags","blobs_url":"https://api.github.com/repos/biota/sourcetracker2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/biota/sourcetracker2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/biota/sourcetracker2/git/refs{/sha}","trees_url":"https://api.github.com/repos/biota/sourcetracker2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/biota/sourcetracker2/statuses/{sha}","languages_url":"https://api.github.com/repos/biota/sourcetracker2/languages","stargazers_url":"https://api.github.com/repos/biota/sourcetracker2/stargazers","contributors_url":"https://api.github.com/repos/biota/sourcetracker2/contributors","subscribers_url":"https://api.github.com/repos/biota/sourcetracker2/subscribers","subscription_url":"https://api.github.com/repos/biota/sourcetracker2/subscription","commits_url":"https://api.github.com/repos/biota/sourcetracker2/commits{/sha}","git_commits_url":"https://api.github.com/repos/biota/sourcetracker2/git/commits{/sha}","comments_url":"https://api.github.com/repos/biota/sourcetracker2/comments{/number}","issue_comment_url":"https://api.github.com/repos/biota/sourcetracker2/issues/comments{/number}","contents_url":"https://api.github.com/repos/biota/sourcetracker2/contents/{+path}","compare_url":"https://api.github.com/repos/biota/sourcetracker2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/biota/sourcetracker2/merges","archive_url":"https://api.github.com/repos/biota/sourcetracker2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/biota/sourcetracker2/downloads","issues_url":"https://api.github.com/repos/biota/sourcetracker2/issues{/number}","pulls_url":"https://api.github.com/repos/biota/sourcetracker2/pulls{/number}","milestones_url":"https://api.github.com/repos/biota/sourcetracker2/milestones{/number}","notifications_url":"https://api.github.com/repos/biota/sourcetracker2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/biota/sourcetracker2/labels{/name}","releases_url":"https://api.github.com/repos/biota/sourcetracker2/releases{/id}","deployments_url":"https://api.github.com/repos/biota/sourcetracker2/deployments","created_at":"2016-03-18T13:33:48Z","updated_at":"2016-05-10T15:24:44Z","pushed_at":"2016-09-07T08:45:51Z","git_url":"git://github.com/biota/sourcetracker2.git","ssh_url":"git@github.com:biota/sourcetracker2.git","clone_url":"https://github.com/biota/sourcetracker2.git","svn_url":"https://github.com/biota/sourcetracker2","homepage":"","size":183,"stargazers_count":2,"watchers_count":2,"language":"Jupyter Notebook","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":17,"forks":4,"open_issues":17,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/biota/sourcetracker2/pulls/71"},"html":{"href":"https://github.com/biota/sourcetracker2/pull/71"},"issue":{"href":"https://api.github.com/repos/biota/sourcetracker2/issues/71"},"comments":{"href":"https://api.github.com/repos/biota/sourcetracker2/issues/71/comments"},"review_comments":{"href":"https://api.github.com/repos/biota/sourcetracker2/pulls/71/comments"},"review_comment":{"href":"https://api.github.com/repos/biota/sourcetracker2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/biota/sourcetracker2/pulls/71/commits"},"statuses":{"href":"https://api.github.com/repos/biota/sourcetracker2/statuses/c3c597086d78adb94b78d56aa71d82ece3688d68"}}}}
{"actor":{"display_login":"gregcaporaso"}}