示例#1
0
 def test_extract_float_from_category(self):
     table = pd.DataFrame({'A': ['1', '2.1', 'note: 3.2', '-3', '-3.0']},
                          dtype='category')
     form = Form(['A'], True, InputNumberType.FLOAT, error_means_null=True)
     result = form.convert_table(table)
     assert_frame_equal(result,
                        pd.DataFrame({'A': [np.nan, 2.1, 3.2, np.nan, -3]}))
示例#2
0
 def test_extract_float_from_category(self):
     table = pd.DataFrame({"A": ["1", "2.1", "note: 3.2", "-3", "-3.0"]},
                          dtype="category")
     form = Form(["A"], True, InputNumberType.FLOAT, error_means_null=True)
     result = form.convert_table(table)
     assert_frame_equal(result,
                        pd.DataFrame({"A": [np.nan, 2.1, 3.2, np.nan, -3]}))
示例#3
0
 def test_extract_float_eu(self):
     table = pd.DataFrame({"A": ["1,234", "2,345.67", "3.456"]})
     form = Form(["A"],
                 True,
                 InputNumberType.FLOAT,
                 InputLocale.EU,
                 error_means_null=True)
     result = form.convert_table(table)
     assert_frame_equal(result, pd.DataFrame({"A": [1.234, 2.345, np.nan]}))
示例#4
0
 def test_error_on_no_match(self):
     table = pd.DataFrame({'A': ['', '.', np.nan, '1', '2.1']})
     form = Form(['A'], True, InputNumberType.INTEGER, InputLocale.US)
     result = form.convert_table(table)
     self.assertEqual(
         result,
         ("'' in row 1 of 'A' cannot be converted. Overall, there are 2 "
          "errors in 1 column. Select 'Convert non-numbers to null' to set "
          "these values to null."))
示例#5
0
 def test_extract_float_eu(self):
     table = pd.DataFrame({'A': ['1,234', '2,345.67', '3.456']})
     form = Form(['A'],
                 True,
                 InputNumberType.FLOAT,
                 InputLocale.EU,
                 error_means_null=True)
     result = form.convert_table(table)
     assert_frame_equal(result, pd.DataFrame({'A': [1.234, 2.345, np.nan]}))
示例#6
0
 def test_match_eu_thousands_must_be_in_groups_of_3(self):
     form = Form(["A"],
                 False,
                 InputNumberType.ANY,
                 InputLocale.EU,
                 error_means_null=True)
     result = form.convert_table(
         pd.DataFrame({"A": ["123.4", "2.345.1", "3.23,123"]}))
     assert_frame_equal(result,
                        pd.DataFrame({"A": [np.nan, np.nan, np.nan]}))
示例#7
0
 def test_extract_integer_from_category(self):
     table = pd.DataFrame({"A": ["1", "2.1", "note: 3.2"]},
                          dtype="category")
     form = Form(["A"], True, InputNumberType.INTEGER)
     result = form.convert_table(table)
     assert_frame_equal(result, pd.DataFrame({"A": [1, 2, 3]}))
示例#8
0
 def test_extract_any_eu_thousands_must_be_in_groups_of_3(self):
     form = Form(["A"], True, InputNumberType.ANY, InputLocale.EU, True)
     result = form.convert_table(
         pd.DataFrame({"A": ["123.4", "2.345.1", "3.23,123"]}))
     assert_frame_equal(result, pd.DataFrame({"A": [123, 2345, 3]}))
示例#9
0
 def test_extract_any_us(self):
     table = pd.DataFrame({"A": ["1,234", "2,345.67", "3.456"]})
     form = Form(["A"], True, InputNumberType.ANY, InputLocale.US)
     result = form.convert_table(table)
     assert_frame_equal(result, pd.DataFrame({"A": [1234, 2345.67, 3.456]}))
示例#10
0
 def test_extract_any_from_category(self):
     table = pd.DataFrame({"A": ["1", "2.1", "note: 3.2"]},
                          dtype="category")
     form = Form(["A"], True, InputNumberType.ANY)
     result = form.convert_table(table)
     assert_frame_equal(result, pd.DataFrame({"A": [1.0, 2.1, 3.2]}))
示例#11
0
 def test_extract_any_eu_thousands_must_be_in_groups_of_3(self):
     form = Form(['A'], True, InputNumberType.ANY, InputLocale.EU, True)
     result = form.convert_table(
         pd.DataFrame({'A': ['123.4', '2.345.1', '3.23,123']}))
     assert_frame_equal(result, pd.DataFrame({'A': [123, 2345, 3]}))
示例#12
0
 def test_extract_any_from_str(self):
     table = pd.DataFrame({'A': ['1', '2.1', 'note: 3.2', '-3.1']})
     form = Form(['A'], True, InputNumberType.ANY, error_means_null=True)
     result = form.convert_table(table)
     assert_frame_equal(result, pd.DataFrame({'A': [1.0, 2.1, 3.2, -3.1]}))
示例#13
0
 def test_replace_with_null(self):
     table = pd.DataFrame({'A': ['', '.', np.nan, '1', '2.1']})
     form = Form(['A'], True, InputNumberType.INTEGER, InputLocale.US, True)
     result = form.convert_table(table)
     assert_frame_equal(result,
                        pd.DataFrame({'A': [np.nan, np.nan, np.nan, 1, 2]}))
示例#14
0
 def test_extract_integer_eu(self):
     table = pd.DataFrame({'A': ['1,234', '2,345.67', '3.456']})
     form = Form(['A'], True, InputNumberType.INTEGER, InputLocale.EU)
     result = form.convert_table(table)
     assert_frame_equal(result, pd.DataFrame({'A': [1, 2, 3456]}))
示例#15
0
 def test_extract_integer_from_category(self):
     table = pd.DataFrame({'A': ['1', '2.1', 'note: 3.2']},
                          dtype='category')
     form = Form(['A'], True, InputNumberType.INTEGER)
     result = form.convert_table(table)
     assert_frame_equal(result, pd.DataFrame({'A': [1, 2, 3]}))
示例#16
0
 def test_extract_integer_eu(self):
     table = pd.DataFrame({"A": ["1,234", "2,345.67", "3.456"]})
     form = Form(["A"], True, InputNumberType.INTEGER, InputLocale.EU)
     result = form.convert_table(table)
     assert_frame_equal(result, pd.DataFrame({"A": [1, 2, 3456]}))
示例#17
0
 def test_extract_any_from_category(self):
     table = pd.DataFrame({'A': ['1', '2.1', 'note: 3.2']},
                          dtype='category')
     form = Form(['A'], True, InputNumberType.ANY)
     result = form.convert_table(table)
     assert_frame_equal(result, pd.DataFrame({'A': [1.0, 2.1, 3.2]}))
示例#18
0
 def test_extract_any_from_str(self):
     table = pd.DataFrame({"A": ["1", "2.1", "note: 3.2", "-3.1"]})
     form = Form(["A"], True, InputNumberType.ANY, error_means_null=True)
     result = form.convert_table(table)
     assert_frame_equal(result, pd.DataFrame({"A": [1.0, 2.1, 3.2, -3.1]}))
示例#19
0
 def test_replace_with_null(self):
     table = pd.DataFrame({"A": ["", ".", np.nan, "1", "2.1"]})
     form = Form(["A"], True, InputNumberType.INTEGER, InputLocale.US, True)
     result = form.convert_table(table)
     assert_frame_equal(result,
                        pd.DataFrame({"A": [np.nan, np.nan, np.nan, 1, 2]}))
示例#20
0
 def test_extract_any_us(self):
     table = pd.DataFrame({'A': ['1,234', '2,345.67', '3.456']})
     form = Form(['A'], True, InputNumberType.ANY, InputLocale.US)
     result = form.convert_table(table)
     assert_frame_equal(result, pd.DataFrame({'A': [1234, 2345.67, 3.456]}))