1

I am introducing unit-testing my python data pipeline using unittest module.

Data class object example:

class IsAvailable(Object)
    employee_id: int = Property()
    start_time: str = Property()

Unit test case:

class TestIsAvailable(TestCase):
    def setUp(self):
        self.employee = pd.read_json('employee_leave.json', orient='records')
        self.isAvailable = IsAvailable()
        self.isAvailable.id = self.employee['start_time'][0]
    def test_is_available_all_day_001(self):
        assert self.isAvailable.start_time == pd.NaT

test result:

self = <tests.test_nodes.TestIsAvailable testMethod=test_is_available_all_day_001>

    def test_is_available_all_day_001(self):
        """test employee is available all day on specific day of the week"""
>       assert self.isAvailable.start_time == pd.NaT
E       AssertionError: assert NaT == NaT
E        +  where NaT = <IsAvailable id=1>.start_time
E        +    where <IsAvailable id=1> = <tests.test_nodes.TestIsAvailable testMethod=test_is_available_all_day_001>.isAvailable
E        +  and   NaT = pd.NaT

How do you test data types?

Adam
  • 473
  • 5
  • 21
  • 1
    `pd.NaT` is not a dtype. Rather, it represents missing values for the datetime dtype. If you want to check for missing values in pandas dataframes, take a look at this answer: https://stackoverflow.com/a/49435999/189418 – foglerit Aug 04 '19 at 01:03

1 Answers1

0

NaN and NaT explicitly do not equal themselves.

You can test this by running python in interactive mode and typing:

import pandas as pd
pd.NaT == pd.NaT

and similarly

pd.NaN == pd.NaN

You can explicitly test for NaN and NaT with

pd.isna(pd.NaT)
Xuth
  • 1
  • 1