Skip to content

Commit

Permalink
- fix issue with TimeSeriesData.LoadFromCsv crashin if csv has just d…
Browse files Browse the repository at this point in the history
…ates but no variables.
  • Loading branch information
Steinar Elgsæter committed Nov 27, 2024
1 parent dd41b82 commit 85f28a6
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 1 deletion.
110 changes: 110 additions & 0 deletions TimeSeriesAnalysis.Tests/TestData/test_edgecase_justdates.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
Time
2024-11-26 12:29:33
2024-11-26 12:30:33
2024-11-26 12:31:33
2024-11-26 12:32:33
2024-11-26 12:33:33
2024-11-26 12:34:33
2024-11-26 12:35:33
2024-11-26 12:36:33
2024-11-26 12:37:33
2024-11-26 12:38:33
2024-11-26 12:39:33
2024-11-26 12:40:33
2024-11-26 12:41:33
2024-11-26 12:42:33
2024-11-26 12:43:33
2024-11-26 12:44:33
2024-11-26 12:45:33
2024-11-26 12:46:33
2024-11-26 12:47:33
2024-11-26 12:48:33
2024-11-26 12:49:33
2024-11-26 12:50:33
2024-11-26 12:51:33
2024-11-26 12:52:33
2024-11-26 12:53:33
2024-11-26 12:54:33
2024-11-26 12:55:33
2024-11-26 12:56:33
2024-11-26 12:57:33
2024-11-26 12:58:33
2024-11-26 12:59:33
2024-11-26 13:00:33
2024-11-26 13:01:33
2024-11-26 13:02:33
2024-11-26 13:03:33
2024-11-26 13:04:33
2024-11-26 13:05:33
2024-11-26 13:06:33
2024-11-26 13:07:33
2024-11-26 13:08:33
2024-11-26 13:09:33
2024-11-26 13:10:33
2024-11-26 13:11:33
2024-11-26 13:12:33
2024-11-26 13:13:33
2024-11-26 13:14:33
2024-11-26 13:15:33
2024-11-26 13:16:33
2024-11-26 13:17:33
2024-11-26 13:18:33
2024-11-26 13:19:33
2024-11-26 13:20:33
2024-11-26 13:21:33
2024-11-26 13:22:33
2024-11-26 13:23:33
2024-11-26 13:24:33
2024-11-26 13:25:33
2024-11-26 13:26:33
2024-11-26 13:27:33
2024-11-26 13:28:33
2024-11-26 13:29:33
2024-11-26 13:30:33
2024-11-26 13:31:33
2024-11-26 13:32:33
2024-11-26 13:33:33
2024-11-26 13:34:33
2024-11-26 13:35:33
2024-11-26 13:36:33
2024-11-26 13:37:33
2024-11-26 13:38:33
2024-11-26 13:39:33
2024-11-26 13:40:33
2024-11-26 13:41:33
2024-11-26 13:42:33
2024-11-26 13:43:33
2024-11-26 13:44:33
2024-11-26 13:45:33
2024-11-26 13:46:33
2024-11-26 13:47:33
2024-11-26 13:48:33
2024-11-26 13:49:33
2024-11-26 13:50:33
2024-11-26 13:51:33
2024-11-26 13:52:33
2024-11-26 13:53:33
2024-11-26 13:54:33
2024-11-26 13:55:33
2024-11-26 13:56:33
2024-11-26 13:57:33
2024-11-26 13:58:33
2024-11-26 13:59:33
2024-11-26 14:00:33
2024-11-26 14:01:33
2024-11-26 14:02:33
2024-11-26 14:03:33
2024-11-26 14:04:33
2024-11-26 14:05:33
2024-11-26 14:06:33
2024-11-26 14:07:33
2024-11-26 14:08:33
2024-11-26 14:09:33
2024-11-26 14:10:33
2024-11-26 14:11:33
2024-11-26 14:12:33
2024-11-26 14:13:33
2024-11-26 14:14:33
2024-11-26 14:15:33
2024-11-26 14:16:33
2024-11-26 14:17:33
110 changes: 110 additions & 0 deletions TimeSeriesAnalysis.Tests/TestData/test_edgecase_justdates2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
Time;
2024-11-26 12:29:33
2024-11-26 12:30:33
2024-11-26 12:31:33
2024-11-26 12:32:33
2024-11-26 12:33:33
2024-11-26 12:34:33
2024-11-26 12:35:33
2024-11-26 12:36:33
2024-11-26 12:37:33
2024-11-26 12:38:33
2024-11-26 12:39:33
2024-11-26 12:40:33
2024-11-26 12:41:33
2024-11-26 12:42:33
2024-11-26 12:43:33
2024-11-26 12:44:33
2024-11-26 12:45:33
2024-11-26 12:46:33
2024-11-26 12:47:33
2024-11-26 12:48:33
2024-11-26 12:49:33
2024-11-26 12:50:33
2024-11-26 12:51:33
2024-11-26 12:52:33
2024-11-26 12:53:33
2024-11-26 12:54:33
2024-11-26 12:55:33
2024-11-26 12:56:33
2024-11-26 12:57:33
2024-11-26 12:58:33
2024-11-26 12:59:33
2024-11-26 13:00:33
2024-11-26 13:01:33
2024-11-26 13:02:33
2024-11-26 13:03:33
2024-11-26 13:04:33
2024-11-26 13:05:33
2024-11-26 13:06:33
2024-11-26 13:07:33
2024-11-26 13:08:33
2024-11-26 13:09:33
2024-11-26 13:10:33
2024-11-26 13:11:33
2024-11-26 13:12:33
2024-11-26 13:13:33
2024-11-26 13:14:33
2024-11-26 13:15:33
2024-11-26 13:16:33
2024-11-26 13:17:33
2024-11-26 13:18:33
2024-11-26 13:19:33
2024-11-26 13:20:33
2024-11-26 13:21:33
2024-11-26 13:22:33
2024-11-26 13:23:33
2024-11-26 13:24:33
2024-11-26 13:25:33
2024-11-26 13:26:33
2024-11-26 13:27:33
2024-11-26 13:28:33
2024-11-26 13:29:33
2024-11-26 13:30:33
2024-11-26 13:31:33
2024-11-26 13:32:33
2024-11-26 13:33:33
2024-11-26 13:34:33
2024-11-26 13:35:33
2024-11-26 13:36:33
2024-11-26 13:37:33
2024-11-26 13:38:33
2024-11-26 13:39:33
2024-11-26 13:40:33
2024-11-26 13:41:33
2024-11-26 13:42:33
2024-11-26 13:43:33
2024-11-26 13:44:33
2024-11-26 13:45:33
2024-11-26 13:46:33
2024-11-26 13:47:33
2024-11-26 13:48:33
2024-11-26 13:49:33
2024-11-26 13:50:33
2024-11-26 13:51:33
2024-11-26 13:52:33
2024-11-26 13:53:33
2024-11-26 13:54:33
2024-11-26 13:55:33
2024-11-26 13:56:33
2024-11-26 13:57:33
2024-11-26 13:58:33
2024-11-26 13:59:33
2024-11-26 14:00:33
2024-11-26 14:01:33
2024-11-26 14:02:33
2024-11-26 14:03:33
2024-11-26 14:04:33
2024-11-26 14:05:33
2024-11-26 14:06:33
2024-11-26 14:07:33
2024-11-26 14:08:33
2024-11-26 14:09:33
2024-11-26 14:10:33
2024-11-26 14:11:33
2024-11-26 14:12:33
2024-11-26 14:13:33
2024-11-26 14:14:33
2024-11-26 14:15:33
2024-11-26 14:16:33
2024-11-26 14:17:33
21 changes: 21 additions & 0 deletions TimeSeriesAnalysis.Tests/Tests/CsvTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ public void CSV_read(string filename)
Assert.AreEqual(new double[,] { { Double.NaN, 1, 2 }, { Double.NaN, 3, 4 }, { Double.NaN, 5, 6 } }, doubleData);
}

[TestCase(@"test_edgecase_justdates.csv", Description = "")]
[TestCase(@"test_edgecase_justdates2.csv", Description = "")]
public void CsvLoadAsTimeSeries_Edgecases_DoesNotCrash(string filename)
{
var ret = CSV.LoadDataFromCsvAsTimeSeries(@"..\..\..\TestData\" + filename, ';', out var dateTimes,
out var variables);
}

[TestCase(@"test_edgecase_justdates.csv", Description = "")]
[TestCase(@"test_edgecase_justdates2.csv", Description = "")]
public void TimeSeriesDataSet_LoadFromCsv_Edgecases_DoesNotCrash(string filename)
{
var csvTxt = File.ReadAllText(@"..\..\..\TestData\"+filename);
var dataset = new TimeSeriesDataSet();
var ret = dataset.LoadFromCsv(new CsvContent(csvTxt),';');
Assert.IsFalse(ret);
}





[TestCase, Explicit]
public void Xml_load()
Expand Down
2 changes: 1 addition & 1 deletion TimeSeriesAnalysis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<RunAnalyzersDuringLiveAnalysis>False</RunAnalyzersDuringLiveAnalysis>
<RepositoryUrl>https://github.com/equinor/TimeSeriesAnalysis.git</RepositoryUrl>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<Version>1.3.39</Version>
<Version>1.3.40</Version>
<Company>Equinor</Company>
<Authors>Equinor</Authors>
<IncludeSymbols>true</IncludeSymbols>
Expand Down
4 changes: 4 additions & 0 deletions TimeSeriesAnalysis/TimeSeriesDataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ private bool Fill(DateTime[] dateTimes, Dictionary<string, double[]> variableDic
{
variableDict.Remove("time");
}
// if the file only included the "time" but no values
if (variableDict.Keys.Count() == 0)
return false;

N = variableDict[variableDict.Keys.First()].Length;
if (N == 0)
{
Expand Down

0 comments on commit 85f28a6

Please sign in to comment.