Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time-zone-aware date handling #63

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions NewareNDA/NewareNDA.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import struct
import warnings
import logging
from datetime import datetime
from datetime import datetime, timezone
import pandas as pd

from NewareNDA.dicts import rec_columns, aux_columns, dtype_dict, \
Expand Down Expand Up @@ -270,7 +270,7 @@ def _bytes_to_list_BTS9(bytes):
Discharge_Capacity/3600,
Charge_Energy/3600,
Discharge_Energy/3600,
datetime.fromtimestamp(Date/1e6)
datetime.fromtimestamp(Date/1e6, timezone.utc).astimezone()
]
return list

Expand Down
5 changes: 3 additions & 2 deletions NewareNDA/NewareNDAx.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import tempfile
import zipfile
import re
from datetime import datetime
from datetime import datetime, timezone
import xml.etree.ElementTree as ET
import pandas as pd

Expand Down Expand Up @@ -207,7 +207,8 @@ def _read_data_runInfo_ndc(file):
rec.append([Time/1000,
Charge_Capacity/3600, Discharge_Capacity/3600,
Charge_Energy/3600, Discharge_Energy/3600,
datetime.fromtimestamp(Timestamp), Step, Index])
datetime.fromtimestamp(Timestamp, timezone.utc).astimezone(),
Step, Index])

# Create DataFrame
df = pd.DataFrame(rec, columns=[
Expand Down
Binary file added tests/nda/mediafire/2-1-6_61[07005012].nda
Binary file not shown.
Binary file added tests/nda/mediafire/2-1-6_62[12500007].nda
Binary file not shown.
Binary file added tests/nda/mediafire/SIM.nda
Binary file not shown.
Binary file added tests/reference/2-1-6_61[07005012].ftr
Binary file not shown.
Binary file added tests/reference/2-1-6_62[12500007].ftr
Binary file not shown.
Binary file added tests/reference/SIM.ftr
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/test_NewareNDA.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import pandas as pd
import NewareNDA
from datetime import datetime


def test_NDA(nda_file, ref_file):
df = NewareNDA.read(nda_file)
ref_df = pd.read_feather(ref_file)

# Convert dates to timestamps for comparison
df['Timestamp'] = df['Timestamp'].apply(datetime.timestamp)
ref_df['Timestamp'] = ref_df['Timestamp'].apply(datetime.timestamp)

pd.testing.assert_frame_equal(df, ref_df, check_like=True)