def check_dtype(field_type, constraints, expectation): field = RecordsSchemaField( name="test", field_type=field_type, constraints=constraints, statistics=None, representations=None, ) out = field.cast_series_type(pd.Series(1, dtype=np.int8)) assert_equal(out.dtype, expectation)
def test_cast_series_type_time_timedelta_entries_zeroed(self): mock_name = Mock(name='name') mock_field_type = 'time' mock_constraints = Mock(name='constraints') mock_statistics = Mock(name='statistics') mock_representations = Mock(name='representations') field = RecordsSchemaField(name=mock_name, field_type=mock_field_type, constraints=mock_constraints, statistics=mock_statistics, representations=mock_representations) data = np.array([pd.Timedelta(hours=0, minutes=0, seconds=0)]) series = pd.Series(data) new_series = field.cast_series_type(series) self.assertEqual(new_series[0], datetime.time(0, 0, 0))
def test_cast_series_type_time_empty(self): mock_name = Mock(name='name') mock_field_type = 'time' mock_constraints = Mock(name='constraints') mock_statistics = Mock(name='statistics') mock_representations = Mock(name='representations') field = RecordsSchemaField(name=mock_name, field_type=mock_field_type, constraints=mock_constraints, statistics=mock_statistics, representations=mock_representations) data = np.array([]) series = pd.Series(data) new_series = field.cast_series_type(series) self.assertIsNotNone(new_series)