Пример #1
0
 def test_convert_null(self):
     result = render(
         pd.DataFrame({"A": [1, np.nan]}),
         {"colnames": ["A"]},
         input_columns={"A": RenderColumn("A", "number", "{:,d}")},
     )
     assert_frame_equal(result, pd.DataFrame({"A": ["1", np.nan]}))
Пример #2
0
 def test_convert_numbers_all_null(self):
     result = render(
         pd.DataFrame({"A": [np.nan, np.nan]}, dtype=np.float64),
         {"colnames": ["A"]},
         input_columns={"A": RenderColumn("A", "number", "{:d}")},
     )
     assert_frame_equal(result, pd.DataFrame({"A": [np.nan, np.nan]}, dtype=object))
Пример #3
0
 def test_convert_str(self):
     result = render(
         pd.DataFrame({"A": ["a"]}),
         {"colnames": ["A"]},
         input_columns={"A": RenderColumn("A", "text", None)},
     )
     assert_frame_equal(result, pd.DataFrame({"A": ["a"]}))
Пример #4
0
 def test_NOP(self):
     # should NOP when first applied
     result = render(
         pd.DataFrame({"A": [0.006]}),
         {"colnames": []},
         input_columns={"A": RenderColumn("A", "number", "{:.2f}")},
     )
     assert_frame_equal(result, pd.DataFrame({"A": [0.006]}))
Пример #5
0
 def test_convert_null(self):
     result = render(
         pd.DataFrame({'A': [1, np.nan]}),
         {'colnames': ['A']},
         input_columns={
             'A': RenderColumn('A', 'number', '{:,d}'),
         }
     )
     assert_frame_equal(result, pd.DataFrame({'A': ['1', np.nan]}))
Пример #6
0
 def test_convert_str(self):
     result = render(
         pd.DataFrame({'A': ['a']}),
         {'colnames': ['A']},
         input_columns={
             'A': RenderColumn('A', 'text', None),
         }
     )
     assert_frame_equal(result, pd.DataFrame({'A': ['a']}))
Пример #7
0
 def test_convert_datetime(self):
     result = render(
         pd.DataFrame(
             {"A": [np.datetime64("2018-01-01"), np.datetime64("2019-02-13")]}
         ),
         {"colnames": ["A"]},
         input_columns={"A": RenderColumn("A", "datetime", None)},
     )
     assert_frame_equal(result, pd.DataFrame({"A": ["2018-01-01", "2019-02-13"]}))
Пример #8
0
 def test_convert_numbers_all_null(self):
     result = render(
         pd.DataFrame({'A': [np.nan, np.nan]}, dtype=np.float64),
         {'colnames': ['A']},
         input_columns={
             'A': RenderColumn('A', 'number', '{:d}'),
         }
     )
     assert_frame_equal(result, pd.DataFrame({'A': [np.nan, np.nan]},
                                             dtype=object))
Пример #9
0
 def test_convert_float(self):
     result = render(
         pd.DataFrame({'A': [1.111], 'B': [2.6]}),
         {'colnames': ['A', 'B']},
         input_columns={
             'A': RenderColumn('A', 'number', '{:.2f}'),
             'B': RenderColumn('B', 'number', '{:d}'),
         }
     )
     assert_frame_equal(result, pd.DataFrame({'A': ['1.11'], 'B': ['2']}))
Пример #10
0
 def test_NOP(self):
     # should NOP when first applied
     result = render(
         pd.DataFrame({'A': [0.006]}),
         {'colnames': []},
         input_columns={
             'A': RenderColumn('A', 'number', '{:.2f}'),
         }
     )
     assert_frame_equal(result, pd.DataFrame({'A': [0.006]}))
Пример #11
0
 def test_convert_float(self):
     result = render(
         pd.DataFrame({"A": [1.111], "B": [2.6]}),
         {"colnames": ["A", "B"]},
         input_columns={
             "A": RenderColumn("A", "number", "{:.2f}"),
             "B": RenderColumn("B", "number", "{:d}"),
         },
     )
     assert_frame_equal(result, pd.DataFrame({"A": ["1.11"], "B": ["2"]}))
Пример #12
0
 def test_convert_datetime(self):
     result = render(
         pd.DataFrame({
             'A': [np.datetime64('2018-01-01'), np.datetime64('2019-02-13')]
         }),
         {'colnames': ['A']},
         input_columns={
             'A': RenderColumn('A', 'datetime', None),
         }
     )
     assert_frame_equal(result,
                        pd.DataFrame({'A': ['2018-01-01', '2019-02-13']}))