Skip to content

Commit d5ec14c

Browse files
committed
string types; release
1 parent ae2aadc commit d5ec14c

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

affinity.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,11 @@ def __init__(self, comment: str, *, value=None, array_class=pd.Series):
457457
super().__init__(object, value, comment, array_class)
458458

459459

460+
class ScalarString(Scalar):
461+
def __init__(self, comment: str, *, value=None, array_class=pd.Series):
462+
super().__init__(pd.StringDtype(), value, comment, array_class)
463+
464+
460465
class ScalarBool(Scalar):
461466
def __init__(self, comment: str, *, value=None, array_class=pd.Series):
462467
super().__init__("boolean", value, comment, array_class)
@@ -497,9 +502,14 @@ def __init__(self, comment: str, *, values=None, array_class=pd.Series):
497502
super().__init__(object, values, comment, array_class)
498503

499504

505+
class VectorString(Vector):
506+
def __init__(self, comment: str, *, values=None, array_class=pd.Series):
507+
super().__init__(pd.StringDtype(), values, comment, array_class)
508+
509+
500510
class VectorBool(Vector):
501511
def __init__(self, comment: str, *, values=None, array_class=pd.Series):
502-
super().__init__("boolean", values, comment, array_class)
512+
super().__init__(np.bool, values, comment, array_class)
503513

504514

505515
class VectorI8(Vector):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "affinity"
7-
version = "0.7.0"
7+
version = "0.8.0"
88
description = "Module for creating well-documented datasets, with types and annotations."
99
authors = [
1010
{ name = "Alex Kislukhin" }

test_affinity.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212

1313
try:
1414
import polars
15+
1516
NO_POLARS = False
1617
except ImportError:
1718
NO_POLARS = True
1819

1920
try:
2021
import pyarrow
22+
2123
NO_PYARROW = False
2224
except ImportError:
2325
NO_PYARROW = True
@@ -54,10 +56,15 @@ def test_empty_vector():
5456
def test_typed_descriptors():
5557
s_untyped = af.ScalarObject("")
5658
assert s_untyped.dtype == object
57-
v_untyped = af.VectorObject("")
59+
v_untyped = af.VectorObject("", values=[0, "0"])
5860
assert v_untyped.dtype == object
59-
v_bool = af.VectorBool("")
60-
assert v_bool.dtype == "boolean"
61+
assert v_untyped._values.values.tolist() == [0, "0"]
62+
v_str = af.VectorString("", values=[0, "0"])
63+
assert v_str.dtype == pd.StringDtype()
64+
assert v_str._values.tolist() == ["0", "0"]
65+
v_bool = af.VectorBool("", values=[False, 1])
66+
assert v_bool.dtype == v_bool.dtype
67+
assert v_bool._values.tolist() == [False, True]
6168
v_i8 = af.VectorI8("")
6269
assert v_i8.dtype == pd.Int8Dtype()
6370
v_i16 = af.VectorI16("")
@@ -228,7 +235,7 @@ class aDataset(af.Dataset):
228235
pd.testing.assert_frame_equal(data.df, data2.df)
229236
assert data.origin.get("source") == "dataframe, shape (2, 3)"
230237
default_dtypes = source_df.dtypes
231-
desired_dtypes = {"v1": "boolean", "v2": np.float32, "v3": pd.Int16Dtype()}
238+
desired_dtypes = {"v1": np.bool, "v2": np.float32, "v3": pd.Int16Dtype()}
232239
pd.testing.assert_frame_equal(data.df, source_df.astype(desired_dtypes))
233240
with pytest.raises(AssertionError):
234241
pd.testing.assert_frame_equal(data.df, source_df.astype(default_dtypes))
@@ -252,7 +259,7 @@ class aDataset(af.Dataset):
252259
data.origin.get("source") == "dataframe, shape (2, 3)\nquery:\nFROM source_df"
253260
)
254261
default_dtypes = source_df.dtypes
255-
desired_dtypes = {"v1": "boolean", "v2": np.float32, "v3": pd.Int16Dtype()}
262+
desired_dtypes = {"v1": np.bool, "v2": np.float32, "v3": pd.Int16Dtype()}
256263
pd.testing.assert_frame_equal(data.df, source_df.astype(desired_dtypes))
257264
with pytest.raises(AssertionError):
258265
pd.testing.assert_frame_equal(data.df, source_df.astype(default_dtypes))

0 commit comments

Comments
 (0)