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

Wrong exception for empty Series #365

Closed
MgSam opened this issue May 30, 2017 · 1 comment
Closed

Wrong exception for empty Series #365

MgSam opened this issue May 30, 2017 · 1 comment
Labels

Comments

@MgSam
Copy link

MgSam commented May 30, 2017

When trying to retrieve an item from an empty series, Deedle throws

System.InvalidOperationException: 'OptionalValue.Value: Value is not available'

rather than an IndexOutOfBoundsException. This misleading exception caused me to spend a lot of time trying to find the problem.

Repro using NUnit:

        [TestCase(true, new object[] { "foo", null})]
        public void SeriesBrokenTest(bool shouldThrow, object[] pairs)
        {
            var dict = arrayToDictionary<string, double?>(pairs);

            var series = dict.ToSeries();
            Assert.Throws<Exception>(() =>
            {
                var newSeries = series.Where(k => k.Value != null).Sort();
                var item = newSeries.GetAt(0); //Throws wrong exception here
            });
        }

        private Dictionary<K, V> arrayToDictionary<K, V>(object[] pairs)
        {
            var dict = new Dictionary<K, V>();
            for (var i = 0; i < pairs.Length - 1; i += 2)
            {
                dict.Add((K)pairs[i], (V)pairs[i + 1]);
            }

            return dict;
        }
@zyzhu
Copy link
Contributor

zyzhu commented Aug 21, 2018

fixed in #437

@zyzhu zyzhu closed this as completed Aug 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants